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 status, orders (the count of orders), and revenue (the summed total_amount) for each status. Order by revenue descending, then status ascending.
Result columns · in this order
statusordersrevenueHow to approach it
GROUP BY status with COUNT(*) AS orders and SUM(total_amount) AS revenue, then ORDER BY revenue DESC, status ASC.
Sample input
| order_id | status | total_amount |
|---|---|---|
| 1001 | paid | 80 |
| 1002 | paid | 120 |
| 1003 | pending | 40 |
| 1004 | shipped | 220 |
| 1006 | refunded | 60 |
| 1010 | paid | 640 |
6 rows — all rows shown.
Expected output
| status | orders | revenue |
|---|---|---|
| paid | 6 | 1585 |
| shipped | 3 | 445 |
| pending | 2 | 70 |
| refunded | 1 | 60 |
4 rows — all rows shown.
Constraints
GROUP BY status. Use COUNT(*) AS orders and SUM(total_amount) AS revenue. Order by revenue DESC, status ASC.
Expected skills
Grouping rows into one summary row per status and ordering grouped output deterministically.
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.