Skip to content

Monthly buyers and growth, with gap months

MediumFull bankPeriod over periodDates and time14 min2 hidden datasets

The task

The growth team charts how many different users buy each month and how that changes.

A buyer in a month is a user with at least one row in purchases whose purchased_at falls in that calendar month. A user counts once per month, however many purchases they made.

For each month from February to June 2025, return:

  • month: the first day of the month
  • buyers: number of distinct buyers that month, 0 if none
  • prev_buyers: number of distinct buyers in the previous calendar month (for February, that is January), 0 if none
  • growth_pct: the change from the previous month as a percentage of the previous month, rounded to 1 decimal place, or NULL when prev_buyers is 0

Sort by month ascending.

Expected output

monthbuyersprev_buyersgrowth_pct
  • Sorted by month ascending.
  • Numbers rounded to 1 decimal place.
  • 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