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
Compare Retention Before Product Change
00:00
5 left

Compare Retention Before Product Change

HardSQL · PostgreSQL

Problem

You are given user signup cohorts and Quora activity events around a product change to the Quora Home Feed launched on 2024-02-01. Write a PostgreSQL query that uses the cohort table to compare retention for users who signed up before vs. after the change. For each cohort month, return the number of users in the cohort, the number of users retained in week 4 (days 21-27 after signup), and the week-4 retention rate. Label each cohort as pre_change or post_change based on the signup date, and order the results chronologically.

Output details

  • Return columns in this order: cohort_month, change_period, cohort_size, retained_users_week_4, week_4_retention_rate.
  • Sort cohort_month in ascending chronological order.
  • Treat signup dates before 2024-02-01 as pre_change and all other signup dates as post_change.
  • Include event dates from signup date plus 21 through plus 27 days, inclusively.
  • Count each retained user at most once, even if multiple qualifying events exist.
  • Round week_4_retention_rate to exactly 4 decimal places, with users having no qualifying event counted as zero retained.

Schema

user_cohorts
ColumnTypeDescription
user_idPKINTUnique user identifier
signup_dateDATEDate the user signed up
cohort_monthDATEFirst day of the user's signup month
quora_events
ColumnTypeDescription
event_idPKINTUnique event identifier
user_idINTUser who generated the event
event_dateDATEDate of the event
surface_nameVARCHAR(50)Quora surface where the event occurred
Tablesuser_cohortsquora_events
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the two 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.