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
Return order_id, total_amount, and order_band for each order. order_band is 'high_value' for total_amount >= 500, 'standard' for >= 100, otherwise 'small'. Order by total_amount descending, then order_id ascending, and return the top 8.
Result columns · in this order
order_idtotal_amountorder_bandHow to approach it
Write a CASE with the >= 500 branch first, alias it order_band, then ORDER BY total_amount DESC, order_id ASC LIMIT 8.
Sample input
| order_id | total_amount |
|---|---|
| 1010 | 640 |
| 1005 | 540 |
| 1004 | 220 |
| 1008 | 150 |
| 1002 | 120 |
| 1011 | 110 |
| 1007 | 95 |
| 1001 | 80 |
| 1003 | 40 |
9 rows — all rows shown.
Expected output
| order_id | total_amount | order_band |
|---|---|---|
| 1010 | 640 | high_value |
| 1005 | 540 | high_value |
| 1004 | 220 | standard |
| 1008 | 150 | standard |
| 1002 | 120 | standard |
| 1011 | 110 | standard |
| 1007 | 95 | small |
| 1001 | 80 | small |
8 rows — all rows shown.
Constraints
Branch order matters: check the highest threshold first so a 640 order is not caught by the 100 branch. Alias the derived column order_band. Use total_amount DESC, order_id ASC as a deterministic sort, limited to 8 rows.
Expected skills
CASE branch ordering, aliasing derived columns, and deterministic ORDER BY with a tie-breaker.
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.