Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Join for Campaign and Conversion

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

Your question is SQL Join for Campaign and Conversion. 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

Andreessen Horowitz uses campaign performance data to evaluate outreach across its founder, technology, and investment content. Write a PostgreSQL query that joins campaign touchpoints with customer conversion records and reports performance for campaigns launched in Q1 2025.

Requirements

  1. Include every Q1 2025 campaign, including campaigns with no recorded touchpoints.
  2. Count distinct customers reached by each campaign.
  3. Count a customer as converted when a conversion occurred within 30 days of that customer's first touch for the campaign.
  4. Calculate the conversion rate as a percentage, returning 0.00 for campaigns with no reached customers. Sort by conversion rate descending, then campaign ID.

Representative sample data

Schema

campaigns
ColumnTypeDescription
campaign_idPKINTUnique campaign identifier
campaign_nameVARCHAR(100)Campaign name
channelVARCHAR(40)Marketing channel
launch_dateDATECampaign launch date
budgetDECIMAL(12,2)Campaign budget
campaign_touches
ColumnTypeDescription
touch_idPKINTUnique touchpoint identifier
campaign_idINTReferences campaigns.campaign_id
customer_idINTCustomer receiving the touch
touched_atDATEDate of the campaign touch
conversions
ColumnTypeDescription
conversion_idPKINTUnique conversion identifier
customer_idINTCustomer who converted
conversion_dateDATEDate of conversion
conversion_typeVARCHAR(40)Type of conversion
Tablescampaignscampaign_touchesconversions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results