Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Conversion Rate by User Segment

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

Your question is Conversion Rate by User Segment. 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

Amazon DSP analysts need to compare advertising performance across audience segments. Using users and impression-level events, write a PostgreSQL query that calculates the user conversion rate during June 2025.

Requirements

  1. Return every user segment, including segments with no impressions during the period. Label users with a missing segment as Unclassified.
  2. Calculate distinct exposed users, distinct converted users, and conversion rate per segment. An impression with clicked = TRUE counts as a conversion.
  3. Restrict events to June 1 through June 30, 2025, and return conversion rate as converted users divided by exposed users. Return 0.0000 when no users were exposed.
  4. Order results alphabetically by segment.

Schema

users
ColumnTypeDescription
user_idPKINTUnique user identifier
user_segmentVARCHAR(30)Amazon DSP audience segment
ad_impressions
ColumnTypeDescription
impression_idPKINTUnique impression identifier
user_idINTUser who received the impression
campaign_nameVARCHAR(100)Amazon DSP campaign name
impression_dateDATEDate when the impression occurred
clickedBOOLEANWhether the impression produced a click
Tablesusersad_impressions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results