Loading problem...
A payroll analytics service stores monthly compensation snapshots in an Employee table:
The pair (id, month) is unique.
Your task is to build a rolling payroll summary for each employee:
Return rows with exactly these columns:
Sort the final table by id ascending, then month descending.
Supported submission environments:
Employee:
| id | month | salary |
|----|-------|--------|
| 1 | 1 | 20 |
| 2 | 1 | 20 |
| 1 | 2 | 30 |
| 2 | 2 | 30 |
| 3 | 2 | 40 |
| 1 | 3 | 40 |
| 3 | 3 | 60 |
| 1 | 4 | 60 |
| 3 | 4 | 70 |
| 1 | 7 | 90 |
| 1 | 8 | 90 |[
{"id":1,"month":7,"rolling_salary":90},
{"id":1,"month":4,"rolling_salary":130},
{"id":1,"month":3,"rolling_salary":90},
{"id":1,"month":2,"rolling_salary":50},
{"id":1,"month":1,"rolling_salary":20},
{"id":2,"month":1,"rolling_salary":20},
{"id":3,"month":3,"rolling_salary":100},
{"id":3,"month":2,"rolling_salary":40}
]For each employee, the most recent month is excluded first, then a 3-month backward sum is computed over existing salary rows only.
Employee:
| id | month | salary |
|----|-------|--------|
| 10 | 1 | 100 |
| 10 | 4 | 300 |
| 10 | 5 | 50 |
| 11 | 2 | 40 |
| 11 | 3 | 60 |
| 11 | 6 | 10 |[
{"id":10,"month":4,"rolling_salary":300},
{"id":10,"month":1,"rolling_salary":100},
{"id":11,"month":3,"rolling_salary":100},
{"id":11,"month":2,"rolling_salary":40}
]Month gaps are not filled with synthetic rows. Missing prior months only contribute zero to the rolling total.
Employee:
| id | month | salary |
|----|-------|--------|
| 21 | 6 | 5000 |
| 22 | 12 | 4000 |[]Each employee has only one row, and that row is their latest month, so everything is excluded.
Constraints