求第二天的温度大于第一天的温度的天气的id 日期的差异=1 datediff(第二天,第一天)=1

注意不可以使用id作为条件, 因为id的自增不一定和日期百分百对应。业务逻辑要求的是日期。

 

上升的温度 第二天的温度大于第一天的天气的id
id recorddate temperature
1 2025-01-01 10
2 2025-01-02 25
3 2025-01-03 20
4 2025-01-04 30
表连接后的表

id recorddate1 recorddate2 temperature1 temperature1
1 2025-01-01 2025-01-02 10 25
select w2.id
from weather w1
join weather w2
on datediff(w2.recorddate,w1.recorddate)=1
and w2.temperature >w1.temperature;

posted @ 2025-04-14 19:07  胖豆芽  阅读(6)  评论(0)    收藏  举报