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:

sql 复制代码
SELECT w.id
FROM weather w
    JOIN weather y
        ON DATEDIFF(w.recordDate, y.recordDate) = 1
WHERE w.temperature > y.temperature
相关推荐
Rookie也要加油2 小时前
02SQLite
数据库·sqlite3
bug菌¹3 小时前
滚雪球学MySQL[4.3讲]:MySQL表设计与优化:正规化、表分区与性能调优详解
数据库·mysql
bug菌¹4 小时前
滚雪球学Oracle[3.1讲]:Oracle SQL基础
数据库·sql·oracle
任风雨4 小时前
场景题1-设计redis的key和value的原则
数据库·redis·缓存
call_me_wangcheng6 小时前
django的模型层介绍与配置
数据库·python·django
人生匆匆7 小时前
bluefs _flush_range allocated: osd用空间但是显示ceph_bluefs_db_used_bytes is 100%
数据库·ceph·servlet
颜淡慕潇7 小时前
【数据库】 MongoDB 撤销用户的角色和权限
数据库·sql·mongodb·nosql
დ旧言~9 小时前
【MySQL】数据类型
android·数据库·mysql·adb
阿桂天山9 小时前
如何通过python+sqlalchemy获得MSsql视图的结构
数据库