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
| id | order_id | amount |
|---|---|---|
| 601 | 101 | 6200 |
| 602 | 102 | 3500 |
| 603 | 103 | 3600 |
| 604 | 104 | 60000 |
| 605 | 105 | 12000 |
| … 23 more rows | ||
orders
| id | customer_id | order_date |
|---|---|---|
| 101 | 1 | 2026-01-05 |
| 102 | 2 | 2026-01-08 |
| 103 | 3 | 2026-01-12 |
| 104 | 1 | 2026-01-20 |
| 105 | 4 | 2026-02-01 |
| … 23 more rows | ||
customers
| id | name | country | signup_date |
|---|---|---|---|
| 1 | Sam | Germany | 2026-01-02 |
| 2 | Nina | Canada | 2026-01-05 |
| 3 | David | Germany | 2026-01-10 |
| 4 | Maya | Japan | 2026-01-15 |
| 5 | Daniel | Canada | 2026-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).”
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.