SQL QuestSQL Interview Questions › Aggregation & Grouping

Month-over-Month Customer Growth

MediumFreeQuerying BasicsAggregation & GroupingWindow FunctionsDate Functions

The marketing team wants a monthly signup momentum report. For each signup_year and signup_month with new customers, show new_signups (COUNT of customers that month), previous_month_signups (last month's count within the same year), difference (this month minus last), and mom_growth_pct (percentage change rounded to 2 decimals). Partition by year so January always resets (LAG returns NULL — that's intentional, not a bug — it's how you say "compare me within my own year only"). Sort by signup_year, then signup_month.

The analytical pattern here is identical to any MoM aggregation: sales MoM, active-user MoM, support-ticket MoM — same shape, different column.

_Inspired by a thread on MoM analysis by [@FortuneDataGuy](https://x.com/FortuneDataGuy). The real skill isn't calculating MoM — it's interpreting what the number means in context. A 100% MoM jump on a small base (1 → 2) is a different story than a 5% jump on a large base (10,000 → 10,500)._

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

customers

customer_idnameemailsignup_datemembershiptotal_orders
1John Smithjohn.smith@email.com2023-01-15Gold15
2Emma Wilsonemma.wilson@email.com2023-03-20Silver8
3Michael Brownmichael.brown@email.com2023-02-10Gold12

Expected output: ~15 rows — one per (year, month), with Jan of each year showing NULL for previous_month_signups

Hint

You need LAG(COUNT(*)) OVER (PARTITION BY year ORDER BY month) — but COUNT has to happen BEFORE LAG can use it. Wrap the GROUP BY aggregation in a subquery, then compute LAG and the difference in the outer query. Use strftime('%Y', signup_date) and strftime('%m', signup_date) for year/month. Subtle: PARTITION BY year means every January's LAG returns NULL — that's the 'reset' pattern. If you wanted MoM across the full timeline (Dec 2023 → Jan 2024 as a real comparison), you'd drop the PARTITION BY.

Concepts

SELECT GROUP BY Aggregation Window Functions LAG Date Functions

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

In these company practice sets

Airbnb · Anthropic · Apple · Databricks · OpenAI · Plaid · Ramp · Revolut · Stripe · Uber · Wise · DoorDash · TikTok

A SQL Quest challenge matched to patterns reported for these companies — not a question any of them has published.

Related questions

Class Survival BreakdownMedium · FreeDepartment Roster with GROUP_CONCATMedium · FreeMovie Rating Tier BreakdownMedium · FreeFull Survival Dashboard by ClassMedium · FreeGenre Financial ReportMedium · FreeDepartment Compensation ReportMedium · 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