SQL Quest › SQL Interview Questions › Aggregation & Grouping
Card Spend by Category, August 2026
The warm-up on a neobank screen: what did people buy last month? The transactions table holds every event on the ledger — card payments, transfers, FX, fees — with a type, a status and an ISO timestamp in ts. Keep only completed card payments made in August 2026 (ts from 2026-08-01 up to but not including 2026-09-01).
Return merchant_category, payments (row count) and spend_gbp (SUM of amount_gbp, rounded to 2 decimals), one row per category. Order by spend_gbp descending.
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
transactions
| txn_id | user_id | ts | type | amount | currency | amount_gbp | fee_gbp | merchant_category | merchant_country | counterparty_user_id | status | decline_reason |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 1 | 2025-06-14 11:01:51 | fx_exchange | 32271.15 | JPY | 167.81 | 1.68 | NULL | NULL | NULL | completed | NULL |
| 2 | 1 | 2025-06-14 11:17:45 | bill_payment | 59.53 | EUR | 50.6 | 0 | utilities | IE | NULL | completed | NULL |
| 3 | 7 | 2025-06-16 10:06:38 | card_payment | 122.27 | EUR | 103.93 | 0 | shopping | ES | NULL | completed | NULL |
Expected output: merchant_category=travel, payments=10, spend_gbp=3437.83 ...
Hint
Concepts
SELECT WHERE GROUP BY SUM COUNT GROUP BY + Filtering
Practise the topic: SQL practice questions · GROUP BY exercises
In these company practice sets
A SQL Quest challenge matched to patterns reported for these companies — not a question any of them has published.
Related questions
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