Write a SQL query to compare pre- and post-launch performance using window functions and date-based grouping.
Use the provided campaign launch dates and daily performance records. Return monthly metrics for each campaign, identify whether each month is before or after launch, and compare each month with the previous month.
campaign_id, campaign_name, performance_month, launch_phase, total_impressions, total_conversions, conversion_rate_pct, prior_month_conversion_rate_pct, and rate_change_pct.campaign_id and performance_month ascending.| Column | Type | Description |
|---|---|---|
| campaign_idPK | INT | Unique campaign identifier |
| campaign_name | VARCHAR(100) | Campaign name |
| launch_date | DATE | Date the campaign launched |
| Column | Type | Description |
|---|---|---|
| performance_idPK | INT | Unique daily performance record identifier |
| campaign_id | INT | Referenced campaign identifier |
| performance_date | DATE | Date of the performance record |
| impressions | INT | Number of ad impressions |
| conversions | INT | Number of attributed conversions |