Weather table, need to show extra columns with nextday temps and diff in todays and nextday temps in sql

Weather table, need to show extra columns with nextday temps and diff in todays and nextday temps in SQL

Tiger Analytics
Input:

Weather table

ID, Date, Temp


Output:

ID, Date, Temp, next_temp, temp_diff


Solution:

select x.*,x.temp-x.next_temp as temp_diff from (select *,lag(temp,1,0) over (order by id)as

 next_temp from weather) as x;

Comments