Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL for Top Channels by CAC

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

Your question is SQL for Top Channels by CAC. Start with the requirements and the three 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

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
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results