Mysql刷題筆記 12.18 查詢與之前(昨天的)日期相比溫度更高的所有日期的 Id

jialun0116發表於2020-12-18

Mysql練習


T1218
+------+------------+------+
| ID   | REDATE     | TEMP |
+------+------------+------+
|    1 | 2020-01-01 |   10 |
|    2 | 2020-01-02 |   18 |
|    3 | 2020-01-03 |   15 |
|    4 | 2020-01-04 |   20 |
+------+------------+------+
結果:
+------+
| ID   |
+------+
|    2 |
|    4 |
+------+

-- 重點是DATE_ADD()和INTERVAL 1 DAY
select b.ID from T1218 a
inner join T1218 b
on DATE_ADD(a.REDATE,INTERVAL 1 day) = b.REDATE
and a.TEMP < b.TEMP

相關文章