Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Conversion Rate by Channel

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

Your question is SQL Conversion Rate by Channel. Start with the requirements and the two 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

Johnson & Johnson marketing analysts need to compare conversion performance across channels for campaigns promoting brands such as TYLENOL, Neutrogena, and BAND-AID Brand. Write a PostgreSQL query that summarizes eligible campaigns during Q1 2025.

Requirements

  1. Include campaigns active at any point between January 1 and March 31, 2025.
  2. Group results by marketing channel, labeling a NULL channel as Unattributed.
  3. Return distinct lead count, distinct conversion count, and conversion rate as a percentage rounded to two decimals.
  4. Include eligible channels with campaigns but no leads, and order by conversion rate descending, then channel ascending.

Schema

campaigns
ColumnTypeDescription
campaign_idPKINTEGERUnique campaign identifier
campaign_nameVARCHAR(100)Campaign name
channelVARCHAR(50)Marketing channel
product_brandVARCHAR(50)Johnson & Johnson brand promoted
start_dateDATECampaign start date
end_dateDATECampaign end date, or NULL if ongoing
campaign_leads
ColumnTypeDescription
lead_idPKINTEGERUnique lead identifier
campaign_idINTEGERCampaign associated with the lead
lead_dateDATEDate the lead was acquired
converted_atDATEDate the lead converted, or NULL if not converted
Tablescampaignscampaign_leads
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results