Affirm risk analytics needs to monitor default rates by loan origination cohort. Write a PostgreSQL query that calculates the default rate for Affirm loans originated during the six complete calendar months ending July 2025.
Use 2025-07-31 as the reporting date. A loan is defaulted when its latest status on or before the reporting date is default.
ROW_NUMBER() to select each loan's latest status.| Column | Type | Description |
|---|---|---|
| application_idPK | INT | Application identifier |
| loan_id | INT | Affirm loan identifier |
| originated_at | DATE | Loan origination date |
| product | VARCHAR(40) | Affirm financing product |
| principal_amount | NUMERIC(12,2) | Original principal amount |
| Column | Type | Description |
|---|---|---|
| status_idPK | INT | Status event identifier |
| loan_id | INT | Related loan identifier |
| status_date | DATE | Date of the status event |
| status | VARCHAR(20) | Loan status |