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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Start free
Retention Rate SQL Query
00:00
5 left

Retention Rate SQL Query

MediumSQL · PostgreSQL

Problem

Remitly wants to measure how consistently newly registered customers complete transfers after signup. Write a PostgreSQL query to calculate monthly retention for the January 2024 signup cohort.

Requirements

  1. Treat users who signed up from 2024-01-01 through 2024-01-31 as the cohort.
  2. Calculate retention for months 0, 1, and 2, where month 0 is January 2024.
  3. Count each user at most once per month, even if they complete multiple transfers.
  4. Return the cohort size, retained users, and retention rate, using all cohort users as the denominator. Order by month number.

Output details

  • Return columns in this order: cohort_month, month_number, cohort_users, retained_users, and retention_rate.
  • Sort by month_number ascending.
  • Round retention_rate to four decimal places.
  • Return NULL for retention_rate when cohort_users is zero.
  • Count completed transfers from 2024-01-01 00:00:00 inclusive through 2024-04-01 00:00:00 exclusive.

Schema

users
ColumnTypeDescription
user_idPKINTUnique Remitly customer identifier
signup_dateDATEDate the customer registered
country_codeVARCHAR(2)Customer registration country
remitly_transfers
ColumnTypeDescription
transfer_idPKINTUnique transfer identifier
user_idINTCustomer who initiated the transfer
completed_atTIMESTAMPTransfer completion timestamp
channelVARCHAR(20)Transfer initiation channel
Tablesusersremitly_transfers
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the two tables are in the Question tab.

Sign up free to run or submit. Log in
CodePostgreSQL
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 1
Run your query to see results here.