Longest run of delivery days per campaign
The task
Campaign managers want to know the longest uninterrupted stretch each campaign served ads. ad_daily has a row for each day a campaign delivered, and no row for a day it did not.
A delivery streak is a run of consecutive calendar days that all have a row for the campaign. For each campaign, find its longest streak. If two streaks of the same campaign are equally long, return the one that started earlier. Return one row per campaign that has at least one row in ad_daily:
campaign_idstreak_start: first day of the streakstreak_end: last day of the streakstreak_days: number of days in the streak
Sort by campaign_id.
Expected output
campaign_idstreak_startstreak_endstreak_days- Sorted by 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
- Listening sessions split by a 30-minute gaphard
- Longest run of consecutive driver cancellationshard
- Merge subscription rows into continuous customer stretcheshard
- Missing inventory snapshot ranges per SKUmedium
- Streaks of four or more days of opening the appmedium
- Ad funnel from impressions to buyers by channelmedium
Loading the editor and PostgreSQL
Loading the editor and PostgreSQL