Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Cohort Analysis SQL

HardSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Cohort Analysis SQL. Start with the requirements and the two tables on the right.

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.

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
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results