Capgemini Invent wants to monitor month-over-month customer retention for its client portal. A retained customer is an eligible customer with portal activity in both the current month and the immediately preceding month.
Write a PostgreSQL query to calculate and compare monthly retention from January through April 2025.
portal_enabled = TRUE.LAG to identify prior-month activity for each customer and to retrieve the previous month's active-customer count and retention rate.NULL when no prior month exists.| Column | Type | Description |
|---|---|---|
| customer_idPK | INT | Unique customer identifier |
| account_id | INT | Client account identifier |
| customer_name | VARCHAR(100) | Customer name |
| status | VARCHAR(20) | Customer lifecycle status |
| Column | Type | Description |
|---|---|---|
| account_idPK | INT | Unique client account identifier |
| account_name | VARCHAR(120) | Client account name |
| portal_enabled | BOOLEAN | Whether portal activity is eligible for retention reporting |
| Column | Type | Description |
|---|---|---|
| activity_idPK | INT | Unique activity event identifier |
| customer_id | INT | Customer who generated the activity |
| activity_date | DATE | Date of portal activity |