Write a SQL query to find the retention rate of Square merchants month-over-month, grouped by the marketing channel they originated from.
Assume a merchant is active in a month when at least one activity record exists. Treat a missing originating channel as Unknown, and calculate retention as the percentage of merchants active in the prior month who are active again in the current month.
activity_month, marketing_channel, retained_merchants, prior_month_merchants, and retention_rate.activity_month, then marketing_channel ascending.| Column | Type | Description |
|---|---|---|
| merchant_idPK | INT | Unique Square merchant identifier |
| marketing_channel | VARCHAR(50) | Marketing channel through which the merchant originated |
| Column | Type | Description |
|---|---|---|
| activity_idPK | INT | Unique merchant activity record identifier |
| merchant_id | INT | Merchant associated with the activity |
| activity_date | DATE | Date on which the merchant was active |