SQL
All Top 50 SQL Interview Questions#17
Compare Sequential Daily Records with Self-Join in SQL
MediumGoogleInterview Question #17
Asked at GoogleGiven a `weather` table with `id`, `record_date`, and `temperature`, write a SQL query to find all record IDs where the temperature was higher than the previous day's (yesterday's) temperature.
Input Table: weather
4 rows preview| id | record_date | temperature |
|---|---|---|
| 1 | 2026-01-01 | 10 |
| 2 | 2026-01-02 | 25 |
| 3 | 2026-01-03 | 20 |
| 4 | 2026-01-04 | 30 |
Expected Output Structure2 rows
| id |
|---|
| 2 |
| 4 |
Interview Context
Asked frequently in data analyst and business analyst technical rounds. Focus on clean filtering, optimal indexing usage, and unambiguous column selection.
PostgreSQL 15
Ready to execute
Click "Run Query" or press Ctrl + Enter to test your query.
Output will be verified against the test dataset.