CODE WORKSPACE

Classify incremental load actions

Return status, orders (the count of orders), and revenue (the summed total_amount) for each status. Order by revenue descending, then status ascending.

GROUP BY status with COUNT(*) AS orders and SUM(total_amount) AS revenue, then ORDER BY revenue DESC, status ASC.

Sample input

ordersA slice of the 12 orders (order_id, status, total_amount shown).
order_idstatustotal_amount
1001paid80
1002paid120
1003pending40
1004shipped220
1006refunded60
1010paid640

Expected output

Expected outputOne summary row per status; revenues add back to 2160. Highest revenue first.
statusordersrevenue
paid61585
shipped3445
pending270
refunded160

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.

SQL
Loading...

AI evaluation

Run the SQL query to inspect preview rows.