Payroll stores one row per employee per month worked in 2025, with pay_month from 1 to 12; months with no work have no row. For each employee, ignore their most recent month. For every other month they worked, compute the total salary for that month plus the two calendar months before it, treating months with no row as 0. Write an SQL query that returns id, pay_month and cumulative_salary. Order the results by id ascending, then pay_month descending.
Loading…
Try solving the question with the schema explorer and hints first. When ready, reveal the verified canonical query and step-by-step logic breakdown.
Ask questions, share alternate queries, and explore solutions
Your recent query executions and answer checks
This will insert the verified MySQL solution into your editor so you can study how each clause transforms the table.