Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Get started
Rank January Experiment Variants by Conversion
00:00
5 left

Rank January Experiment Variants by Conversion

MediumSQL · PostgreSQL

Problem

How would you approach a medium difficulty SQL exercise combined with probability questions in an interview?

Use the provided experiment exposure and conversion-event data. Write a PostgreSQL query that calculates the probability of conversion for each non-null variant in experiment 1 during January 2026, then ranks variants by that probability.

Output

  1. One row per variant, with variant, exposed_exposures, converted_exposures, conversion_probability, and variant_rank.
  2. Include only January exposures belonging to experiment 1 and exclude null variants. Count an exposure as converted when it has at least one conversion event.
  3. Sort by variant_rank ascending, then variant ascending.

Output details

  • Restrict results to experiment name Spotlight Feed in addition to experiment ID 1.
  • Count each distinct exposure_id only once in both exposure and conversion totals.
  • Treat an exposure as converted only when its event type is exactly conversion.
  • Round conversion_probability to 4 decimal places.
  • Rank probabilities in descending order, assigning equal probabilities the same rank.
  • Interpret January 2026 as exposures on or after 2026-01-01 and before 2026-02-01.

Schema

experiments
ColumnTypeDescription
experiment_idPKINTUnique experiment identifier
experiment_nameVARCHAR(100)Experiment display name
statusVARCHAR(20)Experiment lifecycle status
experiment_exposures
ColumnTypeDescription
exposure_idPKINTUnique exposure identifier
experiment_idINTExperiment associated with the exposure
user_idINTUser receiving the exposure
variantVARCHAR(30)Assigned experiment variant
exposed_atDATEDate of exposure
conversion_events
ColumnTypeDescription
event_idPKINTUnique event identifier
exposure_idINTExposure associated with the event
event_typeVARCHAR(30)Type of event recorded
event_atDATEDate of event
Tablesexperimentsexperiment_exposuresconversion_events
Interviewer

Your question is Rank January Experiment Variants by Conversion. 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
Sign up free to run your codeLog inLn 1
Run your query to see results here.