Your question is Compare Current Month Spend vs Budget. 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.
You are given monthly spend and budget data. Write a PostgreSQL query that compares actual versus budgeted spend by department for the current month, returning each department’s actual spend, budgeted spend, variance, and variance percentage. Use the current month based on CURRENT_DATE.
| Column | Type | Description |
|---|---|---|
| department_idPK | INT | Primary key for the department |
| department_name | VARCHAR(100) | Department display name |
| Column | Type | Description |
|---|---|---|
| spend_idPK | INT | Primary key for the spend record |
| department_id | INT | References the department that incurred the spend |
| spend_date | DATE | Date the spend was recorded |
| amount | DECIMAL(12,2) | Actual spend amount |
| Column | Type | Description |
|---|---|---|
| budget_idPK | INT | Primary key for the budget record |
| department_id | INT | References the department assigned the budget |
| budget_month | DATE | First day of the budget month |
| budget_amount | DECIMAL(12,2) | Budgeted spend amount |