Write a SQL query to calculate retention by cohort and month.
Use customer signup dates to define cohorts and card activity dates to identify monthly activity. Include customers with no activity in the cohort size, but report only months with at least one active customer.
cohort_month, month_number, retained_customers, cohort_size, and retention_rate_pct.cohort_month, then month_number ascending. Retention is the percentage of the original cohort active in that elapsed month.| Column | Type | Description |
|---|---|---|
| customer_idPK | INT | Unique customer identifier |
| signup_date | DATE | Date the customer joined |
| customer_segment | VARCHAR(30) | Customer segment |
| Column | Type | Description |
|---|---|---|
| activity_idPK | INT | Unique activity identifier |
| customer_id | INT | Customer associated with the activity |
| activity_date | DATE | Date of card activity |
| activity_type | VARCHAR(30) | Type of card activity |