Write a SQL query to find the total capital expenditure by department for the last fiscal quarter, joining a transactions table with a department mapping table.
Assume fiscal quarters follow calendar quarters, and determine the last fiscal quarter relative to current_date. Include only capital expenditure transactions with a matching department.
department_name and total_capex.total_capex descending, then department_name ascending.| Column | Type | Description |
|---|---|---|
| transaction_idPK | INT | Unique transaction identifier |
| department_code | VARCHAR(10) | Code identifying the responsible department |
| transaction_date | DATE | Date the transaction was recorded |
| transaction_type | VARCHAR(20) | Financial transaction classification |
| amount | DECIMAL(14,2) | Transaction amount in dollars |
| Column | Type | Description |
|---|---|---|
| department_codePK | VARCHAR(10) | Unique department code |
| department_name | VARCHAR(100) | Readable department name |