Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
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 feedbackSuccess 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
SQL for Campaign Performance
00:00
5 left

SQL for Campaign Performance

MediumSQL · PostgreSQL

Problem

Write a SQL query to analyze campaign performance by channel and date, including joins and aggregations across multiple tables at Root.

Use the provided campaign, spend, and event data. Include dates with spend or event activity, even when the corresponding metric is absent.

Output

  1. One row per channel and performance date.
  2. Columns: channel, performance_date, total_spend, total_impressions, total_conversions, total_attributed_revenue, and campaign_count.
  3. Include zero-valued metrics where no activity exists, and order by channel ascending and performance_date ascending.

Schema

campaigns
ColumnTypeDescription
campaign_idPKINTUnique campaign identifier
campaign_nameVARCHAR(100)Root campaign name
channelVARCHAR(30)Marketing acquisition channel
campaign_spend
ColumnTypeDescription
spend_idPKINTUnique spend record identifier
campaign_idINTReferenced campaign
spend_dateDATEDate the spend was recorded
spendDECIMAL(12,2)Marketing spend amount
campaign_events
ColumnTypeDescription
event_idPKINTUnique event summary identifier
campaign_idINTReferenced campaign
event_dateDATEDate the campaign events occurred
impressionsINTNumber of ad impressions
conversionsINTNumber of attributed conversions
attributed_revenueDECIMAL(12,2)Revenue attributed to campaign events
Tablescampaignscampaign_spendcampaign_events
Interviewer

Your question is SQL for Campaign Performance. Start with the requirements and the three 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.