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
相关推荐
zuoerjinshu5 小时前
sql实战解析-sum()over(partition by xx order by xx)
数据库·sql
NocoBase7 小时前
【2.0 教程】第 1 章:认识 NocoBase ,5 分钟跑起来
数据库·人工智能·开源·github·无代码
Hoshino.418 小时前
基于Linux中的数据库操作——下载与安装(1)
linux·运维·数据库
Oueii9 小时前
Django全栈开发入门:构建一个博客系统
jvm·数据库·python
未来龙皇小蓝10 小时前
【MySQL-索引调优】11:Group by相关概念
数据库·mysql·性能优化
2401_8318249610 小时前
使用Fabric自动化你的部署流程
jvm·数据库·python
njidf10 小时前
Python日志记录(Logging)最佳实践
jvm·数据库·python
twc82910 小时前
大模型生成 QA Pairs 提升 RAG 应用测试效率的实践
服务器·数据库·人工智能·windows·rag·大模型测试
@我漫长的孤独流浪10 小时前
Python编程核心知识点速览
开发语言·数据库·python
2401_8512729910 小时前
实战:用Python分析某电商销售数据
jvm·数据库·python