Live campaign days with no delivery
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_idlive_days: the number of live daysmissed_days: how many live days had no rowfirst_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.
| 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