Record click days with a running maximum
The task
The paid-media team celebrates each campaign's best day so far. For every campaign, track its high-water mark of daily clicks during June 2025.
Use the ad_daily rows with a day from 2025-06-01 to 2025-06-30. Days without a row are not rows in the output. For each row return:
campaign_iddayclicksrecord_clicks: the highestclicksvalue the campaign had on any day from 2025-06-01 up to and including this dayis_new_record:trueifclicksis strictly higher than every earlier June day of the same campaign, otherwisefalse. A campaign's first June day counts as a new record. A day that only equals the earlier maximum is not a new record.
Sort by campaign_id, then day.
Expected output
campaign_iddayclicksrecord_clicksis_new_record- Sorted by campaign_id ascending, then day 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