Skip to content

Commit e776abb

Browse files
authored
Create 197. Rising Temperature
1 parent 959dd36 commit e776abb

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

197. Rising Temperature

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/********************
2+
// 197. Rising Temperature
3+
// Given a Weather table, write a SQL query to find all dates' Ids with higher temperature compared to its previous (yesterday's) dates.
4+
5+
+---------+------------------+------------------+
6+
| Id(INT) | RecordDate(DATE) | Temperature(INT) |
7+
+---------+------------------+------------------+
8+
| 1 | 2015-01-01 | 10 |
9+
| 2 | 2015-01-02 | 25 |
10+
| 3 | 2015-01-03 | 20 |
11+
| 4 | 2015-01-04 | 30 |
12+
+---------+------------------+------------------+
13+
For example, return the following Ids for the above Weather table:
14+
+----+
15+
| Id |
16+
+----+
17+
| 2 |
18+
| 4 |
19+
+----+
20+
********************/
21+
22+
# Write your MySQL query statement below
23+
SELECT w2.Id
24+
FROM Weather AS w1
25+
INNER JOIN Weather AS w2
26+
ON w1.Temperature < w2.Temperature
27+
AND DATEDIFF(w2.RecordDate, w1.RecordDate) = 1
28+

0 commit comments

Comments
 (0)