Welcome to the SQL screen.
The question is on your right: Top Monthly Campaign Spend Ranking. Read through the requirements and the three tables first.
Run and submit your code as often as you need. You also have five interviewer messages this session - want to talk through your approach, or are you ready to start coding?
You are given campaign delivery data from StackAdapt and need to identify the top five ad campaigns by total spend for each month in the past year. Write a SQL query that returns one row per campaign-month, ranks campaigns within each month by spend, and keeps only the top five campaigns for each month.
| Column | Type | Description |
|---|---|---|
| campaign_idPK | INT | Primary key for the campaign |
| campaign_name | VARCHAR(100) | Campaign name in StackAdapt |
| advertiser_id | INT | Advertiser that owns the campaign |
| status | VARCHAR(20) | Campaign status |
| Column | Type | Description |
|---|---|---|
| advertiser_idPK | INT | Primary key for the advertiser |
| advertiser_name | VARCHAR(100) | Advertiser name |
| Column | Type | Description |
|---|---|---|
| spend_idPK | INT | Primary key for each spend record |
| campaign_id | INT | Campaign tied to the spend record |
| spend_date | DATE | Date of spend |
| spend_amount | DECIMAL(12,2) | Spend amount for that day |