Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top CTR Campaigns by Day

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Top CTR Campaigns by Day. Start with the requirements and the two tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

PulsePoint needs a daily view of its strongest advertising campaigns. Assume the query runs on 2026-08-29, so the past week is 2026-08-23 through 2026-08-29. Write a PostgreSQL query that returns the top three campaigns by click-through rate for each day with valid campaign metrics.

Requirements

  1. Join daily campaign metrics to campaigns to include the campaign name.
  2. Filter metrics to the inclusive seven-day period ending on CURRENT_DATE, and exclude rows with zero impressions or NULL clicks.
  3. Calculate CTR as clicks divided by impressions, expressed as a percentage rounded to two decimal places.
  4. Rank campaigns independently for each day, returning at most three per day. Break CTR ties with the lower campaign_id.

Schema

campaigns
ColumnTypeDescription
campaign_idPKINTUnique campaign identifier
campaign_nameVARCHAR(100)PulsePoint campaign name
daily_campaign_metrics
ColumnTypeDescription
metric_idPKINTUnique daily metric row identifier
campaign_idINTCampaign associated with the metrics
metric_dateDATEDate on which metrics were recorded
clicksINTNumber of ad clicks
impressionsINTNumber of ad impressions
Tablescampaignsdaily_campaign_metrics
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results