2022/5/3 SQL 197.上升的温度

109 阅读1分钟
  • 特别的日期比较方法DATADIFF

    DATADIFF(date1,date2) = 1 #date1在date2后一天

  • join语句

过程记录

本来想用并集来解决这个问题,但是没有确定的思路,看到题解发现大家都是用join,才明白union不去重的话,实现起来要比联结复杂的多

解决思路

使用日期前后的关系将两个表格联结起来然后检查温度的大小关系,可以得到最终结果

题解

select weather.id as 'id'

from weather

join weather w2 on DATADIFF(weather.recordDate,w2.recordDate)=1

and weather.temperature>w2.temperature)