Write an SQL query to find all dates' id with higher temperature compared to its previous dates (yesterday).
Return the result table in any order.
题意
编写一个 SQL 查询,来查找与之前(昨天的)日期相比温度更高的所有日期的 id 。返回结果 不要求顺序 。解题
首先我们找到每一天的前一天,然后判断温度是否升高了,筛选出温度上升的id即可。select w1.Id as Id
from Weather w1
#连接Weather表(自连接)
inner join Weather w2
#连接条件,w2是w1的前一天
on datediff(w1.RecordDate, w2.RecordDate) = 1
#筛选条件:温度升高
where w1.Temperature > w2.Temperature;
好了,今天的文章就到这里