Your question is SQL Variance Analysis by Region. Start with the requirements and the three tables on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Write a SQL query to analyze monthly operational spend by region, compare it to budget, and flag variances greater than 10%.
Use the provided regional budget and operational spend data. Treat a variance as the percentage difference between actual spend and budget, using the budget as the denominator. Include budgeted region-months even when no spend exists.
region_name, spend_month, actual_spend, budget_amount, variance_amount, variance_pct, and variance_flag| Column | Type | Description |
|---|---|---|
| region_idPK | INT | Unique regional identifier |
| region_name | VARCHAR(100) | Operational region name |
| Column | Type | Description |
|---|---|---|
| budget_idPK | INT | Unique budget record identifier |
| region_id | INT | References the budgeted region |
| month_start | DATE | First day of the budget month |
| budget_amount | NUMERIC(12,2) | Approved operational budget for the region and month |
| Column | Type | Description |
|---|---|---|
| spend_idPK | INT | Unique operational spend record identifier |
| region_id | INT | Region associated with the spend |
| month_start | DATE | First day of the spend month |
| amount | NUMERIC(12,2) | Operational spend amount |