Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Retention Cohort SQL

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

Your question is Retention Cohort 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

Rippling Operations needs a monthly retention cohort view for active platform accounts using account activation and activity records. Write a PostgreSQL query that shows how many accounts from each activation cohort were active in each subsequent month.

Requirements

  1. Include only accounts whose current status is active and whose activation date is known.
  2. Define each account's cohort as the month of activated_at.
  3. Count each account at most once per activity month, even if it has multiple activity records.
  4. Return the cohort size, retained account count, month number relative to activation, and retention rate, ordered by cohort and month number.

Schema

accounts
ColumnTypeDescription
account_idPKINTEGERUnique platform account identifier
account_nameVARCHAR(100)Platform account name
activated_atDATEDate the account became active
statusVARCHAR(20)Current account status
account_activity
ColumnTypeDescription
activity_idPKINTEGERUnique activity record identifier
account_idINTEGERRelated account identifier
activity_atDATEDate of account activity
Tablesaccountsaccount_activity
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results