Use LEFT JOIN to include regions with no sales, and handle NULLs with COALESCE
We're evaluating regional expansion for next year. Can you pull a table of all regions with their total revenue and number of sales? I want ALL regions listed even if they haven't had any sales — those gaps are exactly what I'm looking for. Make sure zeros show as 0, not NULL.
| Column | Type | Key |
|---|---|---|
| region_id | INT | PK |
| region_name | TEXT | |
| country | TEXT | |
| timezone | TEXT |
| Column | Type | Key |
|---|---|---|
| sale_id | INT | PK |
| employee_id | INT | FK → dim_employees |
| product_id | INT | FK → dim_products |
| region_id | INT | FK → dim_regions |
| sale_date | TEXT | |
| quantity | INT | |
| revenue | REAL | |
| discount | REAL |
Each hint you reveal reduces the XP you can earn. Try the query first.
Start from dim_regions and LEFT JOIN fact_sales — this keeps all regions even with no matching sales
Use COALESCE(SUM(revenue), 0) so regions with no sales show 0 instead of NULL
GROUP BY region_id and region_name, then ORDER BY total_revenue DESC to surface the biggest opportunities