customer_orders has one row per purchase (user_id, purchase_id). Count the purchases of each user, then for each purchase count return how many users made exactly that many purchases. Output columns: purchase_count, users_num. Order by purchase_count ascending.
| Column | Type |
|---|---|
| user_id | INTEGER |
| purchase_id | INTEGER |
| user_id | purchase_id |
|---|---|
| 1 | 10 |
| 1 | 11 |
| 1 | 12 |
| 2 | 13 |
| 3 | 14 |
| 3 | 15 |
| purchase_count | users_num |
|---|---|
| 1 | 1 |
| 2 | 1 |
| 3 | 1 |
Solve it in the live editor on this page — run on sample data, then submit against hidden tests.
{{ totalCount }} questions in the style asked at Amazon, Microsoft, Google, Meta, Flipkart and more — {{ hardPct }}% Hard. Write SQL in a real database engine in your browser, run it on sample data, then evaluate against hidden tests.
Company tags show where this type of question is commonly reported in interviews. Questions, data and solutions are written by TechTown.
{{ cur.statement }}
No submissions yet. Press Evaluate to submit your query.
{{ solutionSql }}
{{ out.error }}
You have solved your 3 free questions — nice work! Log in (free) to unlock all 150 questions, keep your streak and appear on the leaderboard.