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
相关推荐
2401_8321319515 分钟前
Python单元测试(unittest)实战指南
jvm·数据库·python
打工的小王1 小时前
redis(四)搭建哨兵模式:一主二从三哨兵
数据库·redis·缓存
Anarkh_Lee1 小时前
【小白也能实现智能问数智能体】使用开源的universal-db-mcp在coze中实现问数 AskDB智能体
数据库·人工智能·ai·开源·ai编程
橘子132 小时前
MySQL用户管理(十三)
数据库·mysql
Dxy12393102162 小时前
MySQL如何加唯一索引
android·数据库·mysql
我真的是大笨蛋2 小时前
深度解析InnoDB如何保障Buffer与磁盘数据一致性
java·数据库·sql·mysql·性能优化
怣502 小时前
MySQL数据检索入门:从零开始学SELECT查询
数据库·mysql
shengli7222 小时前
机器学习与人工智能
jvm·数据库·python
2301_765703142 小时前
Python迭代器(Iterator)揭秘:for循环背后的故事
jvm·数据库·python
倔强的石头1062 小时前
关键信息基础设施的数据库选型:高可用、全链路安全与平滑替代的技术实践
数据库·安全·金仓数据库