【Leetcode】SQL-197. 上升的温度

197. 上升的温度

表: Weather

			+---------------+---------+
			| Column Name   | Type    |
			+---------------+---------+
			| id            | int     |
			| recordDate    | date    |
			| temperature   | int     |
			+---------------+---------+

id 是该表具有唯一值的列。
没有具有相同 recordDate 的不同行。
该表包含特定日期的温度信息

编写解决方案,找出与之前(昨天的)日期相比温度更高的所有日期的 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)

sql语句

Create table If Not Exists Weather (Id int, RecordDate date, Temperature int)
Truncate table Weather
insert into Weather (Id, RecordDate, Temperature) values ('1', '2015-01-01', '10');
insert into Weather (Id, RecordDate, Temperature) values ('2', '2015-01-02', '25');
insert into Weather (Id, RecordDate, Temperature) values ('3', '2015-01-03', '20');
insert into Weather (Id, RecordDate, Temperature) values ('4', '2015-01-04', '30');
select a.id from Weather a join Weather b
on a.Temperature>b.Temperature
and datediff(a.RecordDate,b.RecordDate)=1

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值