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 Campaign Performance Query
00:00
5 left

SQL Campaign Performance Query

MediumSQL · PostgreSQL

Problem

Write a SQL query to track campaign performance by channel, including spend, conversions, and conversion rate over time.

Use the provided campaign and daily performance data. Conversion rate should be calculated as conversions divided by clicks, expressed as a percentage. Include only performance dates from January and February 2025.

Output

  1. One row per channel and month.
  2. Columns: channel, performance_month, total_spend, total_conversions, and conversion_rate.
  3. Sort by month ascending, then channel ascending, with NULL channels last.

Schema

campaigns
ColumnTypeDescription
campaign_idPKINTUnique campaign identifier
campaign_nameVARCHAR(120)Campaign name
channelVARCHAR(60)Marketing channel associated with the campaign
campaign_daily_performance
ColumnTypeDescription
performance_idPKINTUnique daily performance record identifier
campaign_idINTCampaign identifier
performance_dateDATEDate of the performance metrics
spendDECIMAL(12,2)Daily advertising spend
conversionsINTNumber of attributed conversions
clicksINTNumber of campaign clicks
Tablescampaignscampaign_daily_performance
Interviewer

Your question is SQL Campaign Performance Query. 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.