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
Cohort Analysis SQL
00:00
5 left

Cohort Analysis SQL

HardSQL · PostgreSQL

Problem

Initio Capital wants to measure how consistently users return to its product after signup. Write a PostgreSQL query that calculates monthly retention cohorts for users who signed up during the three calendar months from January through March 2025.

Requirements

  1. Assign each eligible user to a monthly signup cohort.
  2. Count the total users in each cohort.
  3. Count distinct active users by cohort month and activity month, excluding events before signup and outside the analysis period.
  4. Return retention as a percentage, ordered by cohort month and activity month.

Schema

users
ColumnTypeDescription
user_idPKINTUnique user identifier
emailVARCHAR(255)User email address
signed_up_atTIMESTAMPTimestamp when the user signed up
user_events
ColumnTypeDescription
event_idPKINTUnique event identifier
user_idINTUser associated with the event
occurred_atTIMESTAMPTimestamp when the event occurred
event_typeVARCHAR(50)Type of product activity
Tablesusersuser_events
Interviewer

Your question is Cohort Analysis SQL. Start with the requirements and the two 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.