Find regions above the sales target
Group all orders by region. Return region, COUNT(*) AS order_count and SUM(amount) AS total_amount only for regions whose total_amount is strictly greater than 200. Count orders with NULL amounts too. Row order does not matter.
Difficulty: intermediate
Show hint
HAVING filters aggregate groups after GROUP BY. WHERE filters individual orders before aggregation.
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 | 120 | paid | East |
| 2 | 2 | 100 | paid | East |
| 3 | 3 | 200 | paid | West |
| region | order_count | total_amount |
|---|---|---|
| East | 2 | 220 |