Your question is Track Fund Balance Trends by Period. Start with the requirements and the two 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 fund ledger data and need to prepare a periodic analysis that supports budgeting and forecasting. Write a PostgreSQL query that returns one row per fund per month with the month’s beginning balance, total expenditures, ending balance, and the prior month’s ending balance. Exclude inactive funds and any transactions outside the reporting range.
| Column | Type | Description |
|---|---|---|
| fund_idPK | INT | Primary key for each fund |
| fund_code | VARCHAR(20) | Internal fund identifier |
| fund_name | VARCHAR(255) | Fund name |
| fund_type | VARCHAR(50) | Fund classification |
| is_active | BOOLEAN | Whether the fund is currently active |
| Column | Type | Description |
|---|---|---|
| transaction_idPK | INT | Primary key for each transaction |
| fund_id | INT | Foreign key to funds.fund_id |
| transaction_date | DATE | Transaction posting date |
| transaction_type | VARCHAR(20) | Transaction category: begin_balance, expenditure, or adjustment |
| amount | NUMERIC(12,2) | Signed transaction amount |