Advanced Case 50 of 50

Case 050: The Shape of the Business

customersorderspayments

Alex's final report for the quarter — the one the manager will actually present.

"Could you give me one row per country? I want the whole picture — customers, orders, revenue, revenue per customer — and rank them while you're at it."

The data Alex is looking at

customers
idnamecountrysignup_date
1SamGermany2026-01-02
2NinaCanada2026-01-05
3DavidGermany2026-01-10
4MayaJapan2026-01-15
5DanielCanada2026-01-20
… 5 more rows
orders
idcustomer_idorder_date
10112026-01-05
10222026-01-08
10332026-01-12
10412026-01-20
10542026-02-01
… 23 more rows
payments
idorder_idamount
6011016200
6021023500
6031033600
60410460000
60510512000
… 23 more rows
TASK

Help Alex answer the manager:

“Build one final report: for each country, show total customers, total orders, total revenue, revenue per customer, and each country's rank by revenue.”
SQL editor Ctrl+Enter to run
Write a query above and hit Run to see what comes back.
No hints requested yet — click "Get a hint" when you're stuck.
Alex's final query — this is for reference. Copy it into your own thinking, not into the editor above.
SELECT customers.country, COUNT(DISTINCT customers.id) AS customers, COUNT(DISTINCT orders.id) AS orders, SUM(payments.amount) AS revenue, ROUND(SUM(payments.amount) * 1.0 / COUNT(DISTINCT customers.id), 1) AS revenue_per_customer, RANK() OVER (ORDER BY SUM(payments.amount) DESC) AS revenue_rank FROM customers JOIN orders ON orders.customer_id = customers.id JOIN payments ON payments.order_id = orders.id GROUP BY customers.country ORDER BY revenue_rank;
What that query returns
Case Debrief Capstone: full multi-metric dashboard
  • Fifty cases ago, this looked impossible.
  • Now it's JOIN, GROUP BY, COUNT DISTINCT, SUM, and a window function — every tool from this curriculum, aimed at one real business question.
  • That's the whole trick. And you're not a beginner anymore.

Case closed.

That's all 50 — one last stop.

Next: Final Recap →