Your question is SQL Window Functions for Rolling Metrics. 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.
Snapmint's risk team wants to monitor daily loan defaults and smooth short-term fluctuations. Write a PostgreSQL query that calculates the 30-day rolling average of daily default events for the reporting period from February 1 through February 10, 2025.
loan_defaults to loans so only defaults belonging to known loans are counted.| Column | Type | Description |
|---|---|---|
| loan_idPK | INT | Unique Snapmint loan identifier |
| customer_id | VARCHAR(20) | Snapmint customer identifier |
| product_name | VARCHAR(50) | Financing product associated with the loan |
| Column | Type | Description |
|---|---|---|
| default_event_idPK | INT | Unique default event identifier |
| loan_id | INT | Loan associated with the default event |
| default_date | DATE | Date the loan entered default |
| default_amount | NUMERIC(12,2) | Outstanding amount at default |