Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Cohort Analysis Q1 vs Q2

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

Your question is Cohort Analysis Q1 vs Q2. 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

The Starlink customer portal team wants to compare early engagement for users who signed up during Q1 and Q2 of 2025. Write a PostgreSQL query that produces a three-month retention view for each signup cohort.

Requirements

  1. Include only users who signed up from January 1 through June 30, 2025, and label them Q1 or Q2.
  2. For month offsets 0, 1, and 2 after signup, count distinct users with at least one session_started event during that month.
  3. Return cohort size, active users, and retention percentage, ordered by cohort and month offset.

Schema

users
ColumnTypeDescription
user_idPKINTEGERUnique Starlink customer portal user identifier
signup_dateDATEDate the user created an account
emailVARCHAR(255)User email address
product_events
ColumnTypeDescription
event_idPKINTEGERUnique product event identifier
user_idINTEGERUser associated with the event
event_timestampTIMESTAMPTimestamp when the event occurred
event_typeVARCHAR(50)Name of the recorded product event
Tablesusersproduct_events
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results