Rising Temperature
Problem
Table: Weather
+---------------+---------+
| Column Name | Type |
+---------------+---------+
| id | int |
| recordDate | date |
| temperature | int |
+---------------+---------+
id is the primary key for this table.
This table contains information about the temperature on a certain day.
Write an SQL query to find all dates’ Id
with higher temperatures compared to its previous dates (yesterday).
Return the result table in any order.
Solution
The problem Rising Temperature
can be solved by using the keyword INNER JOIN
along with the function ADDDATE
.
Implementation
# Write your MySQL query statement below
SELECT w1.id AS Id
FROM
weather AS w1
INNER JOIN weather AS w2 ON w1.recordDate = ADDDATE(w2.recordDate, 1)
WHERE w1.temperature > w2.temperature;