Your question is SQL With LAG/LEAD. Start with the requirements and the two 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.
Blend360 analysts monitor campaign performance across marketing channels. Write a PostgreSQL query that summarizes conversions by channel and day, then compares each result with the previous recorded day for that channel.
channel and metric_date, treating rows where all conversion values are NULL as zero.LAG to return the previous recorded day's conversions for each channel.| Column | Type | Description |
|---|---|---|
| campaign_idPK | INT | Unique campaign identifier |
| campaign_name | VARCHAR(100) | Blend360 campaign name |
| channel | VARCHAR(50) | Marketing channel used by the campaign |
| is_active | BOOLEAN | Whether the campaign is currently active |
| Column | Type | Description |
|---|---|---|
| metric_idPK | INT | Unique metric record identifier |
| campaign_id | INT | References campaigns.campaign_id |
| metric_date | DATE | Date on which the metric was recorded |
| conversions | INT | Number of conversions recorded for the campaign |