Your question is SQL Window Functions for Trends. 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.
Duke University research administrators need a monthly view of expenditures recorded for active research grants. Write a PostgreSQL query that summarizes expenditures from January through March 2025 and calculates running totals and moving averages for each grant.
| Column | Type | Description |
|---|---|---|
| grant_idPK | INTEGER | Unique research grant identifier |
| grant_name | VARCHAR(150) | Research grant title |
| principal_investigator | VARCHAR(120) | Principal investigator responsible for the grant |
| status | VARCHAR(20) | Current grant status |
| Column | Type | Description |
|---|---|---|
| expenditure_idPK | INTEGER | Unique expenditure record identifier |
| grant_id | INTEGER | Grant associated with the expenditure |
| expenditure_date | DATE | Date the expenditure was recorded |
| amount | NUMERIC(12,2) | Expenditure amount in US dollars |