Channel share of ad spend, Q1 against Q2
The task
Marketing wants to see how the mix of ad spend moved between the first two quarters of 2025.
Use ad_daily.spend, assigned to a channel through the campaign's channel in campaigns.
- Q1 is 2025-01-01 up to but not including 2025-04-01.
- Q2 is 2025-04-01 up to but not including 2025-07-01.
A channel's share in a quarter is its spend divided by the spend of all channels that quarter, as a percentage.
Return one row for every distinct channel in campaigns, including a channel with no spend in a quarter (its share is 0):
channelq1_share_pct: the channel's Q1 share, rounded to 1 decimal placeq2_share_pct: the channel's Q2 share, rounded to 1 decimal placeshift_pts: Q2 share minus Q1 share in percentage points, calculated from the unrounded shares and then rounded to 1 decimal place
Sort by shift_pts descending, then channel ascending.
Expected output
channelq1_share_pctq2_share_pctshift_pts- Sorted by shift_pts descending, then channel ascending.
- Numbers rounded to 1 decimal place.
- Checked on the sample and on 2 hidden datasets. How grading works
Tables Marketing team · click a name to insert it
campaigns10 rows in the sample
One row per campaign. Key: campaign_id.
| int | Unique id. | |
| text | Name. | |
| text | search, social, video, email or affiliate. | |
| date | First day live. | |
| date | Last day live. NULL if still running. | |
| numeric(10,2) | Budget per day, USD. |
ad_daily969 rows in the sample
One row per campaign per day it served ads. Days with no delivery have no row. Key: campaign_id, day.
| int | The campaign. | |
| date | The day. | |
| int | Times an ad was shown. | |
| int | Clicks. | |
| numeric(10,2) | Money spent, USD. |
signups2,108 rows in the sample
One row per new user. campaign_id is the campaign credited with the sign-up. Key: user_id.
| int | Unique id. | |
| timestamp | When they signed up (UTC). | |
| int | Credited campaign. NULL for organic sign-ups. | |
| text | Two-letter country code. |
purchases2,294 rows in the sample
One row per paid order by a user. Key: purchase_id.
| int | Unique id. | |
| int | Buyer. | |
| timestamp | When (UTC). | |
| numeric(10,2) | Order value, USD. |
Related questions
Loading the editor and PostgreSQL
Loading the editor and PostgreSQL