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
本站资源均来自互联网,仅供研究学习,禁止违法使用和商用,产生法律纠纷本站概不负责!如果侵犯了您的权益请与我们联系!
转载请注明出处: 免费源码网-免费的源码资源网站 » Leecode SQL 197. Rising Temperature 日期差用 DATEDIFF()
发表评论 取消回复