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 Retention Rate SQL
00:00
5 left

Cohort Retention Rate SQL

HardSQL · PostgreSQL

Problem

Affirm wants to measure how consistently customers return to originate additional loans after their first funded loan. Write a PostgreSQL query that calculates monthly retention for customer cohorts formed from January through March 2024.

Treat a customer as retained in a month when they have at least one funded Affirm loan during that month. Report months 0 through 5, where month 0 is the customer's cohort month.

Requirements

  1. Identify each customer's first funded loan month and assign the customer to that monthly cohort.
  2. Count distinct retained customers for every cohort and month offset from 0 through 5, including zero-retention months.
  3. Return the cohort size and retention rate as a percentage, rounded to two decimal places.
  4. Order results by cohort_month and months_since_cohort.

Schema

customers
ColumnTypeDescription
customer_idPKINTUnique customer identifier
customer_nameVARCHAR(100)Customer name
signup_dateDATEDate the customer signed up
acquisition_channelVARCHAR(30)Customer acquisition source
loans
ColumnTypeDescription
loan_idPKINTUnique loan identifier
customer_idINTCustomer who originated the loan
originated_atDATELoan origination date
statusVARCHAR(20)Loan lifecycle status
amountNUMERIC(10,2)Loan principal amount
Tablescustomersloans
Interviewer

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