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
相关推荐
ClouGence21 分钟前
CloudDM 新增支持 GaussDB 与 openGauss:国产数据库管理更高效
数据库·sql·ci/cd
sukalot43 分钟前
window显示驱动开发—在混合系统中使用跨适配器资源
数据库·驱动开发·音视频
洛卡卡了1 小时前
数据库加密方案实践:我们选的不是最完美,但是真的够用了。
数据库·后端·面试
幽络源小助理1 小时前
MySQL实战优化高手教程 – 从架构原理到生产调优
数据库·mysql·架构
Runing_WoNiu2 小时前
Redis主从架构、哨兵模式及集群比较
数据库·redis·架构
考虑考虑3 小时前
postgressql更新时间
数据库·后端·postgresql
甄超锋3 小时前
python sqlite3模块
jvm·数据库·python·测试工具·django·sqlite·flask
HMBBLOVEPDX4 小时前
MySQL的锁:
数据库·mysql
数据皮皮侠5 小时前
最新上市公司业绩说明会文本数据(2017.02-2025.08)
大数据·数据库·人工智能·笔记·物联网·小程序·区块链
小云数据库服务专线5 小时前
GaussDB数据库架构师修炼(十六) 如何选择磁盘
数据库·数据库架构·gaussdb