Beginner Case 15 of 50

Case 015: The VIP List

customersorderspayments

The manager is planning a VIP outreach campaign.

"Could you build me one list — anyone who's spent big, or anyone who orders often? Just make sure no one shows up on it twice."

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 list of customer names containing everyone who has spent over $50,000 total, or placed 4 or more orders — each name appearing only once.”
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.name FROM customers JOIN orders ON customers.id = orders.customer_id JOIN payments ON payments.order_id = orders.id GROUP BY customers.name HAVING SUM(payments.amount) > 50000 UNION SELECT customers.name FROM customers JOIN orders ON customers.id = orders.customer_id GROUP BY customers.name HAVING COUNT(orders.id) >= 4;
What that query returns
Case Debrief UNION
  • UNION stacks the results of two queries and deduplicates automatically.
  • Quick tip: UNION ALL does the same stacking but keeps every row, duplicates included. Use it when someone showing up in both queries should genuinely count twice (like totaling revenue) instead of once.

Case closed.

Ready for the next one?

Next: Case 016 — Revenue by Month →