Write a SQL query using window functions to calculate rolling 7-day CTR by campaign and compare it to the prior period for Known reporting.
Use the provided campaign and daily metric tables. Treat missing or NULL clicks as zero, and only return dates with a complete current 7-day period and complete preceding 7-day period.
campaign_id, then report_date.campaign_id, report_date, rolling_clicks, rolling_impressions, rolling_ctr, prior_period_ctr, and ctr_change_pct.| Column | Type | Description |
|---|---|---|
| campaign_idPK | INT | Unique campaign identifier |
| campaign_name | VARCHAR(100) | Campaign name in Known reporting |
| Column | Type | Description |
|---|---|---|
| campaign_id | INT | Campaign associated with the daily metrics |
| metric_date | DATE | Date of the campaign metrics |
| impressions | INT | Number of ad impressions |
| clicks | INT | Number of ad clicks |