Rising temperature
EasyP2Coding
Table weather:
| Column | Type |
|---|---|
| id | int (primary key) |
| record_date | date |
| temperature | int |
Return the id of every row whose temperature is higher than the temperature on the previous calendar day. The previous day is the date minus one day, not the previous row: a missing day means there is nothing to compare with.
Output column: id.
Schema
CREATE TABLE weather ( id int PRIMARY KEY, record_date date NOT NULL UNIQUE, temperature int NOT NULL );
Example 1
- Input
- weather: (1, 2024-01-01, 10), (2, 2024-01-02, 25), (3, 2024-01-03, 20)
- Output
- id: 2
Example 2
- Input
- weather: (1, 2024-01-01, 10), (2, 2024-01-03, 50)
- Output
- no rows
- Why
- January 2 is missing, so row 2 has no previous day.
Constraints
- PostgreSQL dialect.
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
PostgreSQL
Run checks the 3 visible tests, Submit all 6. ⌘Enter runs, ⌘⇧Enter submits.