Month Over Month
day is a date written as text, like 2026-03-14. Return one row per month that has sales, earliest first: month (the first 7 characters of the date), total (the sum of amount in that month) and growth: how much the total rose from the month before it in the result, as a percentage of that earlier total, rounded to 1 decimal. A fall is negative, and the first month's growth is NULL.
Example 1
sales
| id | day | amount |
|---|---|---|
| 1 | 2026-01-05 | 100 |
| 2 | 2026-01-20 | 100 |
| 3 | 2026-02-01 | 250 |
| 4 | 2026-03-09 | 200 |
returns
| month | total | growth |
|---|---|---|
| 2026-01 | 200 | NULL |
| 2026-02 | 250 | 25.0 |
| 2026-03 | 200 | -20.0 |
Constraints
- Up to 18 sales
- Every
amountis above 0 - No growth is a close call for the rounding
Write it in your browser, against the clock. The model query, with a note on each piece of it, comes after.
More SQL problems
- Moving AverageHard
- Position Over TimeHard
- SessionsHard
- Three Days RunningHard
- Top Two Salaries per DepartmentHard
- Worst DrawdownHard
- Between Two PricesBeginner
- Both ConditionsBeginner