Given a table of user ad-click events, write a SQL query to calculate the rolling 7-day click-through rate (CTR) for each campaign. Use calendar dates, including the current date and previous six days. Count only click and impression events, and return NULL when the rolling impression count is zero.
campaign_id, event_date, and rolling_ctrrolling_ctr is rolling clicks divided by rolling impressions, rounded to four decimal placescampaign_id, then event_date| Column | Type | Description |
|---|---|---|
| event_idPK | INT | Unique identifier for the ad event |
| campaign_id | VARCHAR(50) | Campaign associated with the event |
| event_date | DATE | Calendar date on which the event occurred |
| event_type | VARCHAR(20) | Event classification, either click or impression |