How would you use SQL window functions to compare a publisher's current-day CTR with its 7-day moving average?
Use the supplied daily publisher metrics and publisher reference data. Calculate the comparison for every available publisher and date, including dates where CTR cannot be calculated.
publisher_id, publisher_name, metric_date, current_ctr, moving_avg_7d, and ctr_vs_moving_avg.publisher_id, then metric_date ascending.| Column | Type | Description |
|---|---|---|
| publisher_idPK | INT | Unique publisher identifier |
| publisher_name | VARCHAR(100) | Publisher display name |
| Column | Type | Description |
|---|---|---|
| metric_idPK | INT | Unique daily metric record identifier |
| publisher_id | INT | Publisher associated with the metric |
| metric_date | DATE | Date of the daily metric |
| clicks | INT | Number of ad clicks |
| impressions | INT | Number of ad impressions |