Shopify wants to monitor whether active merchants continue using Shopify across consecutive months. Write a PostgreSQL query that calculates month-over-month retention for each month with a preceding month of activity.
status = 'active'.| Column | Type | Description |
|---|---|---|
| merchant_idPK | INT | Unique Shopify merchant identifier |
| shop_domain | VARCHAR(255) | Shopify shop domain |
| status | VARCHAR(20) | Merchant account status |
| created_at | DATE | Date the merchant account was created |
| Column | Type | Description |
|---|---|---|
| activity_idPK | INT | Unique activity record identifier |
| merchant_id | INT | Referenced merchant identifier |
| activity_type | VARCHAR(50) | Type of merchant activity |
| occurred_at | TIMESTAMP | Timestamp when the activity occurred |