跳到主要内容

197.上升的温度

序号题目难度
197题目链接简单

题目大意​

编写解决方案,找出与之前(昨天的)日期相比温度更高的所有日期的 id 。

返回结果 无顺序要求 。

表: Weather

Column NameType
idint
recordDatedate
temperatureint

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

示例​

输入​

Weather 表:

idrecordDateTemperature
12015-01-0110
22015-01-0225
32015-01-0320
42015-01-0430

输出​

id
2
4

解释​

2015-01-02 的温度比前一天高(10 -> 25) 2015-01-04 的温度比前一天高(20 -> 30)

参考答案​

with t1 as(
select
id
,RecordDate -- today
,Temperature
,date_sub(RecordDate,INTERVAL 1 DAY) as RecordDate_1 -- yesterday
from Weather
)
select
t3.id
from (
select
t1.*
,t2.Temperature as yes_tem
from t1
left join Weather as t2
on t1.RecordDate_1 = t2.RecordDate
) as t3
where (t3.Temperature - yes_tem) is not null
and t3.Temperature - yes_tem > 0
;