SQL QuestSQL Interview Questions › Joins

Signup-Month Cohort Spend

EasyFreeQuerying BasicsJoinsAggregation & Grouping

Do older cardholders spend more? Group accounts into cohorts by the month they signed up (strftime('%Y-%m', signup_at) on the accounts table) and total their card spend from transactions. The join is one-to-many — one account, many transactions — so count accounts with COUNT(DISTINCT a.account_id), or every cohort's size is inflated by its transaction count.

Return signup_month (YYYY-MM), accounts (distinct accounts in the cohort), total_spend (SUM of amount, rounded to 2 decimals), and spend_per_account (total_spend ÷ accounts, rounded to 2 decimals). Order by signup_month ascending.

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

accounts

account_idemailsignup_atcountrydevice_fingerprintip_blockstatus
1user1@example.com2026-02-24T00:00:00.000ZTRdev_13c0cdad41.116.196.153active
2user2@inbox.dev2025-05-13T00:00:00.000ZJPdev_26576d4938.98.201.102active
3user3@inbox.dev2026-04-25T00:00:00.000ZJPdev_42f1a115190.77.45.244flagged

transactions

txn_idaccount_idamounttxn_atmerchant_idlatlngstatus
1149151.842026-03-04T12:39:39.078Z2440.342-74.4092completed
22110.722026-03-04T13:04:50.641Z752.936613.3229completed
335158.782026-03-04T13:27:15.528Z2552.739713.3134completed

Expected output: 2024-11 12 20610.34 1717.53 ...

Hint

FROM accounts a JOIN transactions t ON t.account_id = a.account_id GROUP BY strftime('%Y-%m', a.signup_at). The per-account figure is SUM(t.amount) / COUNT(DISTINCT a.account_id).

Concepts

SELECT JOIN GROUP BY COUNT DISTINCT strftime JOIN + Date Functions

Practise the topic: SQL practice questions · JOIN practice · GROUP BY exercises

In these company practice sets

Capital One · Revolut

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

Related questions

Your First JOINEasy · FreeJOIN with a FilterEasy · FreeLEFT JOIN: Watch the NULLs AppearEasy · FreeCounting Across a JOINEasy · FreeTransaction Share by Merchant CategoryEasy · FreeCard Spend by CountryEasy · 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