Gallagher's customer analytics team wants to monitor whether churn is increasing across its tracked customer portfolio. Write a PostgreSQL query that calculates the monthly churn rate and its rolling average over the most recent six reported months.
Assume each row in customer_monthly_status represents one tracked customer for one month. A customer is churned when lifecycle_status = 'churned'. The latest month in the data defines the end of the six-month reporting period.
| Column | Type | Description |
|---|---|---|
| customer_idPK | INTEGER | Unique customer identifier |
| customer_name | VARCHAR(120) | Customer or organization name |
| company_name | VARCHAR(120) | Organization associated with the customer |
| Column | Type | Description |
|---|---|---|
| status_idPK | INTEGER | Unique monthly status record identifier |
| customer_id | INTEGER | References customers.customer_id |
| month_start | DATE | First day of the reporting month |
| lifecycle_status | VARCHAR(20) | Monthly lifecycle status |