给定一个 Weather 表,编写一个 SQL 查询,来查找与之前(昨天的)日期相比温度更高的所有日期的 Id。
| 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 |
例如,根据上述给定的 Weather 表格,返回如下 Id:
| Id |
|---|
| 2 |
| 4 |
思路:
DATEDIFF(date1, date2)是两个日期的天数差集
题解:
# Write your MySQL query statement below
select w1.id
from weather w1, weather w2
where
datediff(w1.recorddate, w2.recorddate)=1 and w1.temperature>w2.temperature;
来源:CSDN
作者:李昊轩的博客
链接:https://blog.csdn.net/qq_33709508/article/details/104030367