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
SQL for Top Channels by CAC
00:00
5 left

SQL for Top Channels by CAC

HardSQL · PostgreSQL

Problem

Turing's Product Growth team wants to compare acquisition efficiency across marketing channels during January 2025. Write a PostgreSQL query that identifies the top three eligible channels using customer acquisition cost, or CAC, and conversion rate.

Requirements

  1. Aggregate January 2025 marketing spend and lead activity separately by channel before joining them.
  2. Calculate conversion rate as converted leads divided by total leads, expressed as a percentage.
  3. Calculate CAC as total spend divided by converted leads. Exclude channels with fewer than two leads, no spend, or no conversions.
  4. Rank eligible channels by lowest CAC, then highest conversion rate, and return the top three ranked channels.

Schema

marketing_channels
ColumnTypeDescription
channel_idPKINTMarketing channel identifier
channel_nameVARCHAR(100)Marketing channel name
marketing_spend
ColumnTypeDescription
spend_idPKINTSpend record identifier
channel_idINTReferenced marketing channel
spend_dateDATEDate on which spend was recorded
amountNUMERIC(12,2)Marketing spend amount
turing_leads
ColumnTypeDescription
lead_idPKINTLead identifier
channel_idINTChannel that acquired the lead
signup_dateDATEDate the lead signed up
converted_atDATEDate the lead converted, or null if not converted
Tablesmarketing_channelsmarketing_spendturing_leads
Interviewer

Your question is SQL for Top Channels by CAC. 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.