Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Channel Performance by Time in SQL

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

Your question is Channel Performance by Time in SQL. 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

HelloFresh marketing teams need a monthly view of campaign performance across acquisition channels. Write a PostgreSQL query that combines campaign metadata with daily campaign metrics.

Requirements

  1. Aggregate impressions, clicks, conversions, spend, and revenue by calendar month and channel for Q1 2025.
  2. Replace a missing channel with Unknown.
  3. Calculate click-through rate, conversion rate, and return on ad spend. Avoid division-by-zero errors and preserve NULL when a ratio cannot be calculated.
  4. Order the results chronologically, then alphabetically by channel.

Schema

campaigns
ColumnTypeDescription
campaign_idPKINTUnique campaign identifier
campaign_nameVARCHAR(100)HelloFresh campaign name
channelVARCHAR(50)Marketing acquisition channel
campaign_metrics
ColumnTypeDescription
metric_idPKINTUnique daily metric identifier
campaign_idINTReferences campaigns.campaign_id
metric_dateDATEDate represented by the metrics
impressionsINTNumber of delivered impressions
clicksINTNumber of campaign clicks
conversionsINTNumber of attributed conversions
spendDECIMAL(10,2)Advertising spend
revenueDECIMAL(10,2)Attributed revenue
Tablescampaignscampaign_metrics
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results