SQL QuestSQL Interview Questions › Window Functions

YoY Sales Volume Per Borough

HardProQuerying BasicsWindow FunctionsDate FunctionsAggregation & Grouping

Compute year-over-year DEED count change per borough. First aggregate to (borough, year, deed_count) — extract the year from document_date. Then use LAG to get prev year's count. Show borough_code, year, deed_count, prev_year_count, yoy_change. Order by borough, year.

Solve it in the browser editor →

Runs on SQLite in your browser, graded against the expected result, no signup. A wrong answer gets a diagnosis, not just "incorrect".

Schema

sales

document_idrecord_typedoc_typerecorded_boroughdocument_datedocument_amtrecorded_datetime
2025081800333001ADEED12025-08-1410800000002025-08-18
2024012300948001ADEED12024-01-229630000002024-01-24
2025081800439001ADEED12025-08-148100000002025-08-20

Expected output: Year-over-year deal flow trends

Hint

This is a Pro challenge — the hint, the step-by-step tutor and the reference solution open in the app.

Concepts

SELECT Window Functions LAG Date Functions GROUP BY

Practise the topic: SQL practice questions · Window function practice · Date function practice · GROUP BY exercises · Advanced SQL interview questions

Related questions

Cumulative Distinct Customers Over TimeHard · FreeSalary Rank Within DepartmentHard · FreeRunning Total RevenueHard · FreeYear-over-Year GrowthHard · Free7-Day Rolling Revenue AverageHard · FreeMulti-CTE Revenue PipelineHard · Free

Where would this cost you points in an interview?

Ten questions, no signup: a Skillmap across nine SQL skills and the one to fix first.

Take the readiness test