CODE WORKSPACE

Read the status distribution

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

ordersAll 12 orders (order_id and status shown).
order_idstatus
1001paid
1002paid
1003pending
1004shipped
1005paid
1006refunded
1007paid
1008shipped
1009pending
1010paid
1011paid
1012shipped

Expected output

Expected outputCounts per status, most common first. A grouped count is the fastest way to sanity-check a status column.
statusorders
paid6
shipped3
pending2
refunded1

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.

SQL
Loading...

AI evaluation

Run the SQL query to inspect preview rows.