Skip to content

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):

  • channel
  • q1_share_pct: the channel's Q1 share, rounded to 1 decimal place
  • q2_share_pct: the channel's Q2 share, rounded to 1 decimal place
  • shift_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.

intUnique id.
textName.
textsearch, social, video, email or affiliate.
dateFirst day live.
dateLast 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.

intThe campaign.
dateThe day.
intTimes an ad was shown.
intClicks.
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.

intUnique id.
timestampWhen they signed up (UTC).
intCredited campaign. NULL for organic sign-ups.
textTwo-letter country code.
purchases2,294 rows in the sample

One row per paid order by a user. Key: purchase_id.

intUnique id.
intBuyer.
timestampWhen (UTC).
numeric(10,2)Order value, USD.

Related questions

Loading the editor and PostgreSQL