Sign in to run and submit your work
Reading is open to everyone. Running code and saving drafts need an account so your work is yours and comes back on your next visit.
or
CODE WORKSPACE
Account managers want to see each customer's single biggest order — the order itself, not just what it was worth.
Return one row per customer, ordered by customer_id.
Result columns · in this order
customer_id | The customer. |
order_id | Their largest order. |
order_total | What it was worth. |
How to approach it
Work out the maximum per customer once, then join the orders back to it.
Sample input
| order_id | customer_id | placed_at | status | order_total |
|---|---|---|---|---|
| 1001 | c1 | 2026-01-05 10:00:00 | paid | 120 |
| 1002 | c2 | 2026-01-12 14:30:00 | Paid | 80 |
| 1003 | c1 | 2026-01-20 09:15:00 | pending | 45 |
| 1004 | c3 | 2026-01-31 23:30:00 | PAID | 200 |
| 1005 | c2 | 2026-02-01 00:15:00 | paid | 60 |
| 1006 | c4 | 2026-02-03 11:00:00 | paid | 150 |
| 1007 | c3 | 2026-02-10 16:45:00 | refunded | 90 |
| 1008 | c1 | 2026-02-14 12:00:00 | paid | 300 |
| 1009 | c5 | 2026-02-18 08:30:00 | Paid | 75 |
| 1010 | c4 | 2026-02-25 19:20:00 | pending | 85 |
| 1011 | c5 | 2026-02-28 21:00:00 | paid | 130 |
| 1012 | c2 | 2026-03-02 10:10:00 | paid | 95 |
12 rows — scroll inside the table to see them all.
Expected output
| customer_id | order_id | order_total |
|---|---|---|
| c1 | 1008 | 300 |
| c2 | 1012 | 95 |
| c3 | 1004 | 200 |
| c4 | 1006 | 150 |
| c5 | 1011 | 130 |
5 rows — all rows shown.
Constraints
order_id must be the order that actually carries that customer's maximum.order_id in the SELECT alongside a bare MAX(...) and hope it matches — nothing makes it.Worked example
c1 placed three orders: 1001 for 120, 1003 for 45 and 1008 for 300. The answer is order 1008 — and 300 on its own is not the answer, because the question asks which order carried it.
SELECT customer_id, order_id, MAX(order_total) ... GROUP BY customer_id looks like it works. It reports 300 for c1, but the order_id printed beside it is whichever row the engine happened to keep, which may well be 1001. Most engines reject that query outright; SQLite accepts it and quietly returns something plausible, which is worse.
What this tests
That an aggregate collapses a group to a value, so identifying the row behind that value takes a second step rather than an extra column in the SELECT.
Submit for review to find out what your query gets right, what it gets wrong, and how it compares with the best working query for this exercise.
This scenario runs a full workspace — editor, canvas and results side by side. It needs a laptop or desktop to be usable. Open this page on a bigger screen to start building.