Write a SQL query to analyze departmental spending by month, joining budget and transaction tables and handling missing values.
Return monthly results for every department-month appearing in either table. Use the monthly_budgets and transactions tables.
department_id, spending_month, budget_amount, actual_spending, and variancespending_month, then department_id| Column | Type | Description |
|---|---|---|
| budget_idPK | INT | Unique budget record identifier |
| department_id | INT | Department receiving the budget |
| budget_month | DATE | First day of the budget month |
| budget_amount | NUMERIC(12,2) | Approved budget amount for the month |
| Column | Type | Description |
|---|---|---|
| transaction_idPK | INT | Unique transaction identifier |
| department_id | INT | Department charged for the transaction |
| transaction_date | DATE | Date on which the transaction occurred |
| amount | NUMERIC(12,2) | Transaction amount |