1、描述
编写一个 SQL 查询,来查找与之前(昨天的)日期相比温度更高的所有日期的 id 。
返回结果 不要求顺序 。
查询结果格式如下例:
Weather
±—±-----------±------------+
| id | recordDate | Temperature |
±—±-----------±------------+
| 1 | 2015-01-01 | 10 |
| 2 | 2015-01-02 | 25 |
| 3 | 2015-01-03 | 20 |
| 4 | 2015-01-04 | 30 |
±—±-----------±------------+
Result table:
±—+
| id |
±—+
| 2 |
| 4 |
±—+
2015-01-02 的温度比前一天高(10 -> 25)
2015-01-04 的温度比前一天高(20 -> 30)
来源:力扣(LeetCode)
链接:
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
2、关键字
日期,升温,后一天
3、思路
日期有日期的datediff关键字,操作,求差的天数
4、notes
where后面跟的是条件,
and后面接的也是条件
6、code
# Write your MySQL query statement below
select w2.id // 这个id不用加引号,别加
from weather w1, weather w2 // 重命名
where datediff(w2.recordDate,w1.recordDate) = 1 // 后一天
and w1.Temperature < w2.Temperature; // 升温的