D8LooPFocus modeCODE WORKSPACE
Return status and orders, the count of orders for each status, grouped by status and ordered by orders descending, then status ascending.
GROUP BY status with COUNT(*) AS orders, then ORDER BY orders DESC, status ASC.
Sample input
| order_id | status |
|---|---|
| 1001 | paid |
| 1002 | paid |
| 1003 | pending |
| 1004 | shipped |
| 1005 | paid |
| 1006 | refunded |
| 1007 | paid |
| 1008 | shipped |
| 1009 | pending |
| 1010 | paid |
| 1011 | paid |
| 1012 | shipped |
Expected output
| status | orders |
|---|---|
| paid | 6 |
| shipped | 3 |
| pending | 2 |
| refunded | 1 |
Constraints
Use GROUP BY status with COUNT(*) aliased as orders. Order by orders DESC, then status ASC so ties are deterministic.
Expected skills
Grouped counts as a distribution sanity check and deterministic ordering of grouped results.
Run the SQL query to inspect preview rows.