SQLQuokka
Start practicing
QuestionsLearnSandboxFeaturesRoadmapFAQ

Three-Month Salary Window

Unsolved

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.

SQL Query Editor (Ctrl+Enter to run)
0 characters · Valid
Canonical Solution Official

Official Solution is Hidden

Try solving the question with the schema explorer and hints first. When ready, reveal the verified canonical query and step-by-step logic breakdown.

Community Q&A & Discussion

Ask questions, share alternate queries, and explore solutions

0 comments
Asked By:
Classic pattern · not tied to a specific company

Submission History

Your recent query executions and answer checks

Execution Pipeline:
FROM employee_salaries
Full source dataset
12 rows total
Ready. Type a query to see live execution.
Clause: Auto-Sync · AlaSQL Engine