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
SQL Conversion Rate by Region
00:00
5 left

SQL Conversion Rate by Region

MediumSQL · PostgreSQL

Problem

Xiaomi Operations needs to evaluate the regional performance of the Xiaomi 15 product launch. Write a PostgreSQL query that calculates the percentage of exposed users who purchased the launched product during the launch window.

Requirements

  1. Analyze only the Xiaomi 15 launch and exposures within its launch window.
  2. Group results by region, labeling a missing region as Unknown.
  3. Count each exposed user once per region, even if the user received multiple exposures.
  4. Count a user as converted only when they purchased the Xiaomi 15 after exposure and before the launch window ends. Return exposure count, converted-user count, and conversion rate rounded to two decimals, ordered by region.

Output details

  • Return columns named region, exposed_users, converted_users, and conversion_rate, in that order.
  • Order rows by region ascending.
  • Treat launch-window starts as inclusive and ends as exclusive for exposures and purchases.
  • Treat a purchase timestamp equal to exposure time as qualifying.
  • Express conversion_rate as a percentage by multiplying the converted-user proportion by 100.

Schema

product_launches
ColumnTypeDescription
launch_idPKINTUnique product launch identifier
product_idINTProduct identifier
product_nameVARCHAR(100)Product name
launch_startTIMESTAMPInclusive start of the launch window
launch_endTIMESTAMPExclusive end of the launch window
launch_exposures
ColumnTypeDescription
exposure_idPKINTUnique exposure identifier
launch_idINTReferences product_launches.launch_id
user_idINTUser exposed to the launch
regionVARCHAR(50)User region
exposed_atTIMESTAMPTime of product exposure
purchases
ColumnTypeDescription
purchase_idPKINTUnique purchase identifier
user_idINTUser who made the purchase
product_idINTPurchased product identifier
purchased_atTIMESTAMPPurchase timestamp
Tablesproduct_launcheslaunch_exposurespurchases
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the three tables are in the Question tab.

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.