Beginner
Case 10 of 50
Case 010: The Big Spenders
customersorders
The order-count numbers from the loyalty tiers came back, and something looks off — a customer with ten $50 orders is outranking someone who placed three $3,000 orders.
"Order count doesn't tell me revenue," the manager says. "Could you show me who's actually spent the most — over $5,000 total? That's what should count for a VIP tier."
The data Alex is looking at
customers
| id | name | country |
|---|---|---|
| 1 | Sam | Germany |
| 2 | Nina | Canada |
| 3 | David | Brazil |
| 4 | Maya | Japan |
| 5 | Daniel | Australia |
| … 1 more row | ||
orders
| id | customer_id | product | amount | order_date |
|---|---|---|---|---|
| 101 | 1 | Keyboard | 2500 | 2026-01-05 |
| 102 | 3 | Mouse | 1200 | 2026-01-08 |
| 103 | 2 | Headphones | 3500 | 2026-01-10 |
| 104 | 4 | Monitor | 12000 | 2026-01-12 |
| 105 | 1 | Webcam | 4500 | 2026-02-03 |
| … 4 more rows | ||||
TASK
Help Alex answer the manager:
“Find every customer whose combined order total is more than $5,000, showing that total.”
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,
SUM(orders.amount) AS total_spent
FROM customers
JOIN orders ON customers.id = orders.customer_id
GROUP BY customers.name
HAVING SUM(orders.amount) > 5000;
What that query returns
Case Debrief
GROUP BY, SUM, HAVING
- HAVING filters grouped rows AFTER aggregation happens — exactly what you need when the condition depends on an aggregate like SUM(), not a raw column value.