SQL Quest › SQL Interview Questions › Subqueries & CTEs

Top Buyers by Volume

MediumFreeQuerying BasicsSubqueries & CTEsJoinsAggregation & Grouping

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". Free accounts get 10 free challenge solves, and this can be one of them.

Schema

sales

document_idrecord_typedoc_typerecorded_boroughdocument_datedocument_amtrecorded_datetime
2025081800333001ADEED12025-08-1410800000002025-08-18
2024012300948001ADEED12024-01-229630000002024-01-24
2025081800439001ADEED12025-08-148100000002025-08-20

sales_parties

document_idparty_typeparty_rolename
20260302001740051SELLERRIVER'S EDGE
20260302004230051SELLERSTANLEY AVENUE PRESERVATION HDFC
20260302004230052BUYERNEW YORK CITY HOUSING DEVELOPMENT CORPORATION

Expected output: Most active buyers

Hint

The hint for this one spells out most of the query, so it stays in the editor. Reach for 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

Read the concept: Recursive CTE explained

Related questions

Above-Median NPL BanksMedium · FreeActive and Recently FailedMedium · FreeAbove-Average-Assess PropertiesMedium · FreeCombined Sales and Permits ActivityMedium · FreeAbove-Average Tool WearMedium · FreeTop Failure Mode by QualityMedium · 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