Top Customers
What you're building
A leaderboard of customers ranked by how much they've spent β used in CRM dashboards, loyalty programs, and churn analysis.
Requirements
Join orders, products, and customers. Return:
nameβ customer nametotal_spentβ total money spent (price Γ quantity summed)order_countβ number of orders placed
Order by total_spent descending. Include all customers who placed at least one order.
Tables: customers(id, name, city) Β· orders(id, customer_id, product_id, quantity) Β· products(id, price)
Stretch goals
- Show only the top 3 with
LIMIT 3. - Add
cityto the output so you can see geographic patterns.
What this proves
Multi-table joins, aggregation, and ranking β the exact triad tested in SQL screens at every tech company.
β‘ 40 XP
query.sqlRuns in your browser (SQLite/WASM)
Loading editorβ¦
Tests1 to pass
Customers ranked by total spend
Run your code to check these.