Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Channel Performance by Time in SQL
00:00
5 left

Channel Performance by Time in SQL

MediumSQL · PostgreSQL

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
Interviewer

Your question is Channel Performance by Time in SQL. Start with the requirements and the two tables in the Question tab.

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.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.