<aside> 💡

Project Overview:

This project identifies dates where the temperature was higher than the previous day. The solution demonstrates SQL techniques like self-joins and date difference calculations.

</aside>


Problem Description:

Table: Weather

The task is to find the ids of dates where the temperature was higher compared to the previous day.


Solution:

The query uses a self-join on the Weather table to compare each date's temperature with the temperature of the previous day.

SELECT W2.id
FROM Weather W1
JOIN Weather W2
ON DATEDIFF(W2.recordDate, W1.recordDate) = 1
WHERE W2.temperature > W1.temperature;


Explanation:

  1. Self-Join:
  2. Temperature Comparison:
  3. Selecting IDs:

Example Input and Output:

Input: