Write a SQL query using window functions to compute a rolling 7-day average of impressions and clicks by publisher.
Use the publisher_daily_metrics table, which contains one row per publisher per calendar date. Calculate averages over the current date and up to the six preceding dates.
publisher_name, metric_date, rolling_7_day_avg_impressions, and rolling_7_day_avg_clicks.publisher_name and metric_date ascending.The window covers the current metric date and the 6 calendar days before it; dates with no rows are simply absent from the window, and all rows for the same publisher and date share one window.
| 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 daily metrics |
| metric_date | DATE | Calendar date of the metrics |
| impressions | NUMERIC(12,2) | Daily ad impressions |
| clicks | NUMERIC(12,2) | Daily ad clicks |