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
相关推荐
笃行客从不躺平25 分钟前
遇到大SQL怎么处理
java·开发语言·数据库·sql
逻极1 小时前
Redis Queue (RQ) 核心原理:轻量任务队列的设计与实践(一句话讲透核心本质)
数据库·redis·bootstrap
q***31831 小时前
Window下Redis的安装和部署详细图文教程(Redis的安装和可视化工具的使用)
数据库·redis·缓存
大锦终2 小时前
【MySQL】基本查询
数据库·mysql
last_zhiyin2 小时前
Oracle sql tuning guide 翻译 Part 6-5 --- Hint使用报告的操作方法和例子
数据库·sql·oracle·sql tunning
Rysxt_2 小时前
Spring Boot SPI 教程
java·数据库·sql
避避风港3 小时前
MySQL 从入门到实战
数据库·mysql
s***4533 小时前
MSSQL2022的一个错误:未在本地计算机上注册“Microsoft.ACE.OLEDB.16.0”提供程序
数据库·microsoft
能鈺CMS3 小时前
能鈺CMS · 虚拟发货源码
java·大数据·数据库
泡沫·4 小时前
4.iSCSI 服务器
运维·服务器·数据库