SQL Quest › SQL Interview Questions › Subqueries & CTEs
Top Buyers by Volume
Find the top 10 buyers (party_role='BUYER') by total deal volume in the sales sample. JOIN sales_parties to sales to get document_amt per buyer. Sum amount per buyer. Show buyer_name, deal_count, total_volume. Order by total_volume 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
sales
| document_id | record_type | doc_type | recorded_borough | document_date | document_amt | recorded_datetime |
|---|---|---|---|---|---|---|
| 2025081800333001 | A | DEED | 1 | 2025-08-14 | 1080000000 | 2025-08-18 |
| 2024012300948001 | A | DEED | 1 | 2024-01-22 | 963000000 | 2024-01-24 |
| 2025081800439001 | A | DEED | 1 | 2025-08-14 | 810000000 | 2025-08-20 |
sales_parties
| document_id | party_type | party_role | name |
|---|---|---|---|
| 2026030200174005 | 1 | SELLER | RIVER'S EDGE |
| 2026030200423005 | 1 | SELLER | STANLEY AVENUE PRESERVATION HDFC |
| 2026030200423005 | 2 | BUYER | NEW YORK CITY HOUSING DEVELOPMENT CORPORATION |
Expected output: Most active buyers
Hint
SELECT, CTE, JOIN, and open the hint there if you stall.Concepts
SELECT CTE JOIN GROUP BY
Practise the topic: SQL practice questions · CTE practice · JOIN practice · GROUP BY exercises
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