SQL QuestSQL Interview Questions › Joins

Top-up Methods by Plan

MediumFreeQuerying BasicsJoinsAggregation & Grouping

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_iduser_idtsamountcurrencyamount_gbpmethod
112025-06-04 00:00:00117.65EUR100apple_pay
242025-06-04 03:00:00750PLN150bank_transfer
322025-06-05 02:00:00117.65EUR100bank_transfer

users

user_idsignup_datecountryhome_currencyplanplan_sincekyc_verified_atreferred_bybirth_year
12025-06-01IEEURstandard2025-06-012025-06-03 16:00:00NULL1972
22025-06-02FREURstandard2025-06-022025-06-04 16:00:00NULL1979
32025-06-03GBGBPstandard2025-06-032025-06-08 04:00:00NULL1977

Expected output: plan=metal, method=bank_transfer, top_ups=22, total_gbp=7346 ...

Hint

The count condition is on the group, not the row, so it belongs in HAVING COUNT(*) >= 20 after GROUP BY u.plan, t.method.

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

Revolut

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

Related questions

Customers Who Never OrderedMedium · FreeAbove-Average Departments (Derived Table)Medium · FreeLEFT JOIN NULL Semantics: Inactive CustomersMedium · FreeManagement Hierarchy OverviewMedium · FreeCount Direct ReportsMedium · FreeCustomer Recency AnalysisMedium · 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