Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Channels by Conversion Rate

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

Your question is Top Channels by Conversion Rate. Start with the requirements and the four 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

Rocket's Marketing Analytics team wants to evaluate acquisition performance for the Rocket App. Write a PostgreSQL query that identifies the top three marketing channels by monthly conversion rate.

Requirements

  1. Derive the month from each session's session_at timestamp.
  2. Calculate conversion rate as distinct converted sessions divided by distinct sessions, multiplied by 100.
  3. Prevent multiple conversion events for one session from inflating the conversion count.
  4. Rank channels independently within each month using ROW_NUMBER(), ordering by conversion rate descending, then session volume descending, then channel name ascending.
  5. Return only the top three channels for each month from January through March 2025.

Schema

channels
ColumnTypeDescription
channel_idPKINTMarketing channel identifier
channel_nameVARCHAR(100)Marketing channel name
campaigns
ColumnTypeDescription
campaign_idPKINTCampaign identifier
channel_idINTChannel associated with the campaign
campaign_nameVARCHAR(150)Campaign name
sessions
ColumnTypeDescription
session_idPKBIGINTRocket App visitor session identifier
campaign_idINTAttributed campaign identifier
session_atTIMESTAMPTZSession start timestamp
conversions
ColumnTypeDescription
conversion_idPKBIGINTConversion event identifier
session_idBIGINTSession that generated the conversion
converted_atTIMESTAMPTZConversion event timestamp
conversion_typeVARCHAR(50)Type of conversion event
Tableschannelscampaignssessionsconversions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results