Skip to content

Live campaign days with no delivery

HardFull bankDates and timeRows with no matchAnalytics engineering22 min2 hidden datasets

The task

Ad ops suspects some campaigns stopped serving on days they were supposed to be live. ad_daily has no row for a day with no delivery, so the gaps are the days that are missing.

A campaign's live days run from started_on to its last live day, inclusive. The last live day is ended_on, or 2025-06-30 when ended_on is NULL or later than 2025-06-30. A live day is missed when the campaign has no ad_daily row for that day. Rows on days outside the live days are ignored.

Return one row for each campaign with at least one missed day:

  • campaign_id
  • live_days: the number of live days
  • missed_days: how many live days had no row
  • first_missed_day: the earliest missed day, as a date

Sort by missed_days descending, then campaign_id ascending.

Expected output

campaign_idlive_daysmissed_daysfirst_missed_day
  • Sorted by missed_days descending, then campaign_id ascending.
  • 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