Beginner Case 14 of 50

Case 014: Small, Medium, or Large

paymentsorderscustomers

The manager wants payments bucketed for a quick visual report.

"I don't need exact numbers — could you just label each one Small, Medium, or Large? And a name on each row instead of an order ID would save me from having to look each one up."

The data Alex is looking at

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

Help Alex answer the manager:

“Show every payment with the customer's name, labeling each payment as 'Small' (under $5,000), 'Medium' ($5,000–$20,000), or 'Large' (over $20,000).”
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, payments.amount, CASE WHEN payments.amount < 5000 THEN 'Small' WHEN payments.amount <= 20000 THEN 'Medium' ELSE 'Large' END AS size_label FROM payments JOIN orders ON orders.id = payments.order_id JOIN customers ON customers.id = orders.customer_id;
What that query returns
Case Debrief CASE expressions
  • CASE WHEN...THEN...ELSE...END evaluates conditions in order and returns the first match — it's how you turn raw numbers into business categories.
  • In this query, the CASE block sits right in the SELECT list next to customers.name and payments.amount, as just another column (size_label). It doesn't change anything else — the JOINs to orders and customers still work exactly the same.

Case closed.

Ready for the next one?

Next: Case 015 — The VIP List →