Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Conversion Rate SQL Join
00:00
5 left

Conversion Rate SQL Join

MediumSQL · PostgreSQL

Problem

Business Context

Amplify Marketing Agency needs a campaign performance view that compares the number of customers assigned to each campaign with the number who converted.

Task

Write a PostgreSQL query that joins customers, campaigns, and conversions to calculate conversion performance for every campaign.

Requirements

  1. Return every campaign, including campaigns with no assigned customers or conversions.
  2. Show assigned customer count, distinct converted customer count, and conversion rate as a percentage rounded to two decimals.
  3. Count each customer at most once per campaign, even if the customer has multiple conversion events.
  4. Order results by campaign_id ascending.

Schema

campaigns
ColumnTypeDescription
campaign_idPKINTUnique campaign identifier
campaign_nameVARCHAR(100)Amplify campaign name
channelVARCHAR(50)Marketing channel
customers
ColumnTypeDescription
customer_idPKINTUnique customer identifier
customer_nameVARCHAR(100)Customer name
campaign_idINTCampaign assigned to the customer
conversions
ColumnTypeDescription
conversion_idPKINTUnique conversion event identifier
customer_idINTCustomer associated with the conversion
campaign_idINTCampaign credited for the conversion
converted_atDATEDate of the conversion event
Tablescustomerscampaignsconversions
Interviewer

Your question is Conversion Rate SQL Join. 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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.