How would you use SQL window functions to compute running totals or retention metrics?
Write a PostgreSQL query that calculates monthly policyholder retention metrics from signup and activity records. Include only activity occurring in or after the policyholder's signup month, and ignore records without a valid signup or activity date.
cohort_month, activity_month, retained_policyholders, cohort_size, and retention_ratecohort_month, then activity_month ascending| Column | Type | Description |
|---|---|---|
| policyholder_idPK | INTEGER | Unique policyholder identifier |
| signup_date | DATE | Date the policyholder joined |
| Column | Type | Description |
|---|---|---|
| activity_idPK | INTEGER | Unique activity record identifier |
| policyholder_id | INTEGER | Policyholder associated with the activity |
| activity_date | DATE | Date of the policyholder activity |