Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Daily Retention Rate Query

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

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

Paytm wants to measure how consistently users who signed up in the previous quarter return to the Paytm app. For this exercise, assume the reporting date is 2024-07-01, so the last quarter is 2024-04-01 through 2024-06-30.

Write a PostgreSQL query that calculates daily retention for days 0 through 7 after signup.

Requirements

  1. Include users whose signup_date falls within the last quarter.
  2. Treat a user as retained on day N when they have at least one activity on signup_date + N days.
  3. Use the full signup cohort as the denominator for every retention day, including users with no activity.
  4. Count each user at most once per retention day and return zero-retention days.
  5. Return retention_day, cohort_users, retained_users, and retention_rate, ordered by retention_day.

Schema

users
ColumnTypeDescription
user_idPKINTUnique Paytm user identifier
signup_dateDATEDate when the user registered
acquisition_channelVARCHAR(30)Channel associated with signup
user_activity
ColumnTypeDescription
activity_idPKINTUnique activity record identifier
user_idINTUser associated with the activity
activity_atTIMESTAMPTimestamp when the activity occurred
activity_typeVARCHAR(30)Type of Paytm activity
Tablesusersuser_activity
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results