leetcode-SQL-197. 上升的温度

简介: leetcode-SQL-197. 上升的温度

题目

题目链接

表: Weather

+---------------+---------+
| Column Name   | Type    |
+---------------+---------+
| id            | int     |
| recordDate    | date    |
| temperature   | int     |
+---------------+---------+
id 是这个表的主键
该表包含特定日期的温度信息

编写一个 SQL 查询,来查找与之前(昨天的)日期相比温度更高的所有日期的 id 。

返回结果 不要求顺序 。

查询结果格式如下例。

示例 1:

输入:
Weather 表:
+----+------------+-------------+
| id | recordDate | Temperature |
+----+------------+-------------+
| 1  | 2015-01-01 | 10          |
| 2  | 2015-01-02 | 25          |
| 3  | 2015-01-03 | 20          |
| 4  | 2015-01-04 | 30          |
+----+------------+-------------+
输出:
+----+
| id |
+----+
| 2  |
| 4  |
+----+
解释:
2015-01-02 的温度比前一天高(10 -> 25)
2015-01-04 的温度比前一天高(20 -> 30)

解题

主要是datediff的使用,计算两个日期之差

select a.id
from Weather as a
inner join Weather as b
on datediff(a.recordDate,b.recordDate)=1
where a.temperature>b.temperature;
相关文章
|
1月前
|
C++
leetcode739 每日温度
leetcode739 每日温度
|
1月前
|
算法
代码随想录算法训练营第五十七天 | LeetCode 739. 每日温度、496. 下一个更大元素 I
代码随想录算法训练营第五十七天 | LeetCode 739. 每日温度、496. 下一个更大元素 I
26 3
|
1月前
|
存储 算法
代码随想录算法训练营第五十九天 | LeetCode 739. 每日温度、496. 下一个更大元素 I
代码随想录算法训练营第五十九天 | LeetCode 739. 每日温度、496. 下一个更大元素 I
27 1
|
1月前
|
索引
leetcode代码记录(每日温度
leetcode代码记录(每日温度
20 0
|
1月前
|
容器
代码随想录 Day49 单调栈01 LeetCode LeetCodeT739每日温度 T496 下一个最大元素I
代码随想录 Day49 单调栈01 LeetCode LeetCodeT739每日温度 T496 下一个最大元素I
43 0
|
1月前
|
索引
leetcode-739:每日温度
leetcode-739:每日温度
30 0
【LeetCode-每日一题】-739-每日温度
【LeetCode-每日一题】-739-每日温度
|
10月前
力扣739 每日温度
力扣739 每日温度
43 0
|
测试技术 数据库
LeetCode(数据库)- 上升的温度
LeetCode(数据库)- 上升的温度
121 0
|
存储
LeetCode 739. 每日温度
LeetCode 739. 每日温度
70 0
LeetCode 739. 每日温度