Skip to content

Seven-day buyer rate by campaign

HardFull bankConditional aggregationJoinsRatios and percentages25 min2 hidden datasets

The task

Marketing judges each campaign by how many of its sign-ups buy within a week.

A user is a seven-day buyer when they have at least one purchase with purchased_at from their signed_up_at (inclusive) up to signed_up_at + 7 days (not included). A user with several such purchases counts once.

Count users by the campaign credited in signups.campaign_id; organic sign-ups (NULL campaign) are not part of any campaign. Return one row for every campaign in campaigns, including campaigns with no sign-ups:

  • campaign_id
  • signups: number of users credited to the campaign
  • buyers_7d: number of those users who are seven-day buyers
  • buyer_pct: buyers_7d as a percentage of signups, rounded to 1 decimal place, or NULL when the campaign has no sign-ups

Sort by campaign_id ascending.

Expected output

campaign_idsignupsbuyers_7dbuyer_pct
  • Sorted by campaign_id 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