Leecode SQL 197. Rising Temperature 日期差用 DATEDIFF

Write a solution to find all dates’ id with higher temperatures compared to its previous dates (yesterday).

Return the result table in any order.

Input
Weather =

id recordDate temperature
1 2015-01-01 10
2 2015-01-02 25
3 2015-01-03 20
4 2015-01-04 30

Output

id
2
4

记住!!不可以写 w.recordDate = y.recordDate+ 1 因为是日期,跨月份会找不出来!
要写 DATEDIFF(w.recordDate, y.recordDate) = 1

My solution:

SELECT w.id
FROM weather w
    JOIN weather y
        ON DATEDIFF(w.recordDate, y.recordDate) = 1
WHERE w.temperature > y.temperature
上一篇:netty之Netty与SpringBoot整合


下一篇:面向对象的三大特性:封装、继承、多态