【LeetCode】打卡--SQL197. 上升的温度

【LeetCode】打卡–SQL197. 上升的温度

题目

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

+---------+------------------+------------------+
| Id(INT) | RecordDate(DATE) | Temperature(INT) |
+---------+------------------+------------------+
|       1 |       2015-01-01 |               10 |
|       2 |       2015-01-02 |               25 |
|       3 |       2015-01-03 |               20 |
|       4 |       2015-01-04 |               30 |
+---------+------------------+------------------+

例如,根据上述给定的 Weather 表格,返回如下 Id:

+----+
| Id |
+----+
|  2 |
|  4 |
+----+

解答

/* Write your T-SQL query statement below */
Select W1.Id
From Weather As W1,Weather As W2
Where W1.RecordDate = Dateadd(Day,1,W2.RecordDate)
And W1.Temperature > W2.Temperature

我们下次再见,如果还有下次的话!!!
欢迎关注微信公众号:516数据工作室
516数据工作室

猜你喜欢

转载自blog.csdn.net/Asher117/article/details/88842417