Change From the Day Before
prices has one closing price per day. Return every day and change: that day's close minus the close of the day before it in the table. The first day has no day before, so its change is NULL. Earliest day first.
Example 1
prices
| day | close |
|---|---|
| 2026-01-05 | 101.5 |
| 2026-01-02 | 100.0 |
| 2026-01-06 | 99.25 |
returns
| day | change |
|---|---|
| 2026-01-02 | NULL |
| 2026-01-05 | 1.5 |
| 2026-01-06 | -2.25 |
Constraints
- Up to 12 days, each day once
Write it in your browser, against the clock. The model query, with a note on each piece of it, comes after.
More SQL problems
- First OrderMedium
- Latest PriceMedium
- More Than the ManagerMedium
- Open PositionsMedium
- Rank in the DepartmentMedium
- Revenue per CityMedium
- Running BalanceMedium
- Second From the TopMedium