Seven-day moving average of sign-ups
The task
The growth team charts daily sign-ups with a 7-day moving average. Build the June 2025 numbers.
For every day from 2025-06-01 to 2025-06-30, return:
day: the datesignups: sign-ups that day (0 if there were none)avg_7d: the average daily sign-ups over that day and the 6 days before it, where a day with no sign-ups counts as 0, rounded to 2 decimal places
The window for June 1 reaches back to May 26. Sort by day.
Expected output
daysignupsavg_7d- Sorted by day ascending.
- Numbers rounded to 2 decimal places.
- 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