Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Cohort Analysis Q1 vs Q2
00:00
5 left

Cohort Analysis Q1 vs Q2

HardSQL · PostgreSQL

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
Interviewer

Your question is Cohort Analysis Q1 vs Q2. 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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.