Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
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
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
Build my plan
Conversion Rate Change with CTEs
00:00
5 left

Conversion Rate Change with CTEs

MediumSQL · PostgreSQL

Problem

Context

Capgemini Government Solutions wants to evaluate whether product changes improve user conversion behavior. Each product change should be compared with activity during the 30 days immediately before and after the change.

Task

Write a PostgreSQL query using CTEs and joins to compare conversion rates for every valid product change.

Requirements

  1. Classify each visit as before or after based on a 30-day window around change_date.
  2. Use a LEFT JOIN so products with no visits remain in the result.
  3. Calculate visits, converted visits, and conversion rates for both periods. Use NULL for a rate when the period has no visits.
  4. Return the conversion-rate change as after_rate - before_rate, ordered by product_id.

Schema

product_changes
ColumnTypeDescription
change_idPKINTUnique product change identifier
product_idINTProduct associated with the change
change_dateDATEDate the product change took effect
change_labelVARCHAR(100)Short description of the change
product_visits
ColumnTypeDescription
visit_idPKINTUnique product visit identifier
product_idINTProduct viewed during the visit
visitor_idINTAnonymous or authenticated visitor identifier
visited_atDATEDate of the product visit
conversions
ColumnTypeDescription
conversion_idPKINTUnique conversion identifier
visit_idINTVisit that produced the conversion
converted_atDATEDate of conversion
Tablesproduct_changesproduct_visitsconversions
Interviewer

Your question is Conversion Rate Change with CTEs. 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.