Rising Temperature
Task: Find all dates’ Id with higher temperatures compared to its previous dates (yesterday).
Table: Weather
| Column Name | Type |
|---|---|
| id | INT |
| recordDate | date |
| temperature | INT |
Input: Weather table:
| id | recordDate | temperature |
|---|---|---|
| 1 | 2015-01-01 | 10 |
| 2 | 2015-01-02 | 25 |
| 3 | 2015-01-03 | 20 |
| 4 | 2015-01-04 | 30 |
Output:
| id |
|---|
| 2 |
| 4 |
View Reference Solution & Explanation ▼
This solution uses a `JOIN` to combine data from multiple tables and date functions to handle time-based filtering or grouping.
SELECT w1.id FROM Weather w1 JOIN Weather w2 ON DATE(w1.recordDate, '-1 day') = w2.recordDate WHERE w1.temperature > w2.temperature;