Summarize sales by region
Return region and SUM(amount) AS total_amount for every region represented in orders, including a NULL region. Do not filter by status. If a region has only NULL amounts, its total_amount must be NULL. Row order does not matter.
Difficulty: beginner
Show hint
GROUP BY region creates one result row per region. SUM ignores NULL values but returns NULL when all inputs are NULL.
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 | 50 | paid | East |
| 2 | 2 | 80 | pending | West |
| 3 | 1 | 70 | paid | East |
| region | total_amount |
|---|---|
| East | 120 |
| West | 80 |