Рет қаралды 32
Leetcode SQL: Question 197 Rising Temperature
This SQL script is used to find days when the temperature was higher than the previous day. Let's break it down step-by-step:
SELECT w2.id:
This part selects the id from the table Weather. The id likely represents a unique identifier for each weather record.
FROM Weather w1 INNER JOIN Weather w2 ON w1.recordDate = w2.recordDate - 1:
This joins the Weather table with itself. We're calling the first instance w1 and the second instance w2.
The condition w1.recordDate = w2.recordDate - 1 means we're comparing each weather record (w2) with the record from the previous day (w1).
WHERE w2.temperature is greater than w1.temperature:
This filters the results to include only those days (w2) where the temperature was higher than the previous day (w1).
In Summary
This SQL query identifies days when the temperature increased compared to the previous day by:
Selecting the unique identifier (id) for each weather record.
Joining the Weather table with itself to compare consecutive days.
Filtering to include only those days with a higher temperature than the previous day.