*LeetCode Mysql根据日期差异,查询差异数据

给定一个 Weather 表,来查找与之前(昨天的)日期相比温度更高的所有日期的 Id。

Weather:

Id(INT) RecordDate(DATE) Temperature(INT)
1 2015-01-01 10
2 2015-01-02 25
3 2015-01-03 20
4 2015-01-04 30

答:

select 
    w1.Id 
from  
    Weather w1 join Weather w2 
    on 
        w1.Temperature > w2.Temperature 
    and 
        dateDiff(w1.RecordDate, w2.RecordDate) = 1 

结果:

Id
2
4

猜你喜欢

转载自blog.csdn.net/weixin_44355591/article/details/106094953