Write a query to calculate the churn rate by cohort over the last four quarters.
Use the customers and transactions tables. A customer is active in a quarter when they have at least one completed transaction. Churn is the percentage of customers active in the immediately preceding quarter who are not active in the reporting quarter. Use the latest quarter represented in transactions as the endpoint.
cohort_quarter, reporting_quarter, active_customers_previous_quarter, churned_customers, and churn_ratecohort_quarter, then reporting_quarter| Column | Type | Description |
|---|---|---|
| customer_idPK | INT | Unique customer identifier |
| signup_date | DATE | Customer signup date used to assign the cohort |
| Column | Type | Description |
|---|---|---|
| transaction_idPK | INT | Unique transaction identifier |
| customer_id | INT | Customer associated with the transaction |
| transaction_date | DATE | Date of the transaction |
| transaction_status | VARCHAR(20) | Transaction outcome, such as completed or cancelled |