Count orders and total their value
Return one row with total_orders (the number of orders, including rows with a NULL amount) and total_amount (the sum of non-NULL amounts). Return 0 for total_amount when there are no amounts to sum. Use these exact column aliases.
Difficulty: beginner
Show hint
COUNT(*) counts rows. SUM ignores NULL; COALESCE can replace a NULL aggregate with 0.
Tables and sample data
Each test starts with fresh tables. Result rows may be returned in any order. Column names and column order must match.
| order_id (integer) | customer_id (integer) | amount (numeric) | status (text) | region (text) |
|---|---|---|---|---|
| 1 | 1 | 25.5 | paid | East |
| 2 | 2 | 40 | pending | West |
| 3 | 3 | NULL | paid | North |
| total_orders | total_amount |
|---|---|
| 3 | 65.5 |