SQL Quest › SQL Interview Questions › Joins
Top-up Methods by Plan
WHERE filters rows, HAVING filters groups — the distinction one candidate was asked to explain out loud. Join top_ups to users and count top-ups per plan and method, with their total value.
Return plan, method, top_ups (row count) and total_gbp (SUM of amount_gbp, rounded to 2 decimals), but only the plan-method pairs with at least 20 top-ups. Order by plan ascending, then total_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
top_ups
| top_up_id | user_id | ts | amount | currency | amount_gbp | method |
|---|---|---|---|---|---|---|
| 1 | 1 | 2025-06-04 00:00:00 | 117.65 | EUR | 100 | apple_pay |
| 2 | 4 | 2025-06-04 03:00:00 | 750 | PLN | 150 | bank_transfer |
| 3 | 2 | 2025-06-05 02:00:00 | 117.65 | EUR | 100 | bank_transfer |
users
| user_id | signup_date | country | home_currency | plan | plan_since | kyc_verified_at | referred_by | birth_year |
|---|---|---|---|---|---|---|---|---|
| 1 | 2025-06-01 | IE | EUR | standard | 2025-06-01 | 2025-06-03 16:00:00 | NULL | 1972 |
| 2 | 2025-06-02 | FR | EUR | standard | 2025-06-02 | 2025-06-04 16:00:00 | NULL | 1979 |
| 3 | 2025-06-03 | GB | GBP | standard | 2025-06-03 | 2025-06-08 04:00:00 | NULL | 1977 |
Expected output: plan=metal, method=bank_transfer, top_ups=22, total_gbp=7346 ...
Hint
Concepts
SELECT JOIN GROUP BY HAVING SUM COUNT JOIN + HAVING
Practise the topic: SQL practice questions · JOIN practice · 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