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 分钟前
记录一次0丢失的ORA-00354: 损坏重做日志块标头故障恢复---惜分飞
数据库·oracle
cspttty27 分钟前
2026秋招供应链分析师技能栈:SQL、Excel、BI与业务分析
数据库·sql·excel
Omics Pro1 小时前
澳科大:自进化AI虚拟细胞
数据库·人工智能·算法·机器学习·自然语言处理
ShineWinsu1 小时前
对于MySQL:索引的解析
linux·数据库·mysql·面试·笔试·索引·海量数据
我是苏苏1 小时前
Redis开发09:Windows系统下主从复制的配置教程
数据库·redis·缓存
数据狐(Datafox)1 小时前
京东商品列表API接口解析(附 JSON 样例)
数据库·爬虫·json
troy12812 小时前
向量数据库选型指南:Milvus / Qdrant / Chroma / pgvector
数据库·milvus
彧azz13 小时前
Redis 全面指南:从核心概念到高可用架构实战
数据库·redis·架构
DBA小马哥13 小时前
MongoDB 数据同步怎么做?oplog、Change Streams、同步工具 4 种方案一次讲清(附踩坑清单)
数据库·mongodb