每日一题-8(上升的温度)

题8:

根据下面的表,编写一个SQL来查找与之前(昨天的)日期相比温度更高的所有日期的id.
在这里插入图片描述
解题思路:这是需要比较日期的,引入DATEDIFF()函数来比较两个日期类型的值,然后利用自连接,代码如下:

select a.id
from Weather as a 
inner join Weather as b
on datediff(a.recordDate,b.recordDate) = 1
where a.Temperature>b.Temperature ;

猜你喜欢

转载自blog.csdn.net/Txixi/article/details/121265810