D8LooPFocus modeCODE WORKSPACE
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
| order_id | status | total_amount |
|---|---|---|
| 1001 | paid | 80 |
| 1002 | paid | 120 |
| 1003 | pending | 40 |
| 1004 | shipped | 220 |
| 1006 | refunded | 60 |
| 1010 | paid | 640 |
Expected output
| status | orders | revenue |
|---|---|---|
| paid | 6 | 1585 |
| shipped | 3 | 445 |
| pending | 2 | 70 |
| refunded | 1 | 60 |
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.
Run the SQL query to inspect preview rows.