Skip to content

Click-through rate by campaign

The task

The marketing team reports the click-through rate (CTR) of each campaign: all the clicks it received divided by all the impressions it served, over every day in ad_daily.

Return one row per campaign that has at least one row in ad_daily:

  • campaign_name
  • ctr_pct, the CTR as a percentage (0 to 100), rounded to 2 decimal places

A campaign whose rows add up to zero impressions has no CTR, so return NULL for it. Sort by ctr_pct descending, then campaign_name ascending.

Expected output

campaign_namectr_pct
  • Sorted by ctr_pct descending, then campaign_name 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.

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