Your question is SQL Month-Over-Month Campaign Comparison. Start with the requirements and the three tables on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Targetbase needs a monthly performance view for campaign optimization across its activation channels. Write a PostgreSQL query that compares each active campaign's metrics from January through April 2025.
LAG to return prior-month revenue.NULL when prior revenue is zero or unavailable.| Column | Type | Description |
|---|---|---|
| campaign_idPK | INT | Campaign identifier |
| campaign_name | VARCHAR(150) | Campaign name |
| channel_id | INT | References channels.channel_id |
| objective | VARCHAR(80) | Campaign objective |
| start_date | DATE | Campaign start date |
| end_date | DATE | Campaign end date |
| Column | Type | Description |
|---|---|---|
| channel_idPK | INT | Channel identifier |
| channel_name | VARCHAR(80) | Targetbase activation channel |
| platform | VARCHAR(60) | Delivery platform |
| Column | Type | Description |
|---|---|---|
| metric_datePK | DATE | Metric date |
| campaign_idPK | INT | References campaigns.campaign_id |
| impressions | INT | Delivered impressions |
| clicks | INT | Recorded clicks |
| spend | NUMERIC(12,2) | Daily spend |
| conversions | INT | Attributed conversions |
| revenue | NUMERIC(12,2) | Attributed revenue |