Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Calculate 30-Day User Retention

MediumSQL · PostgreSQL00:00
I
Practice interviewer
Your interviewer
In session
I
Interviewer

Welcome to the SQL screen.

The question is on your right: Calculate 30-Day User Retention. Read through the requirements and the three tables first.

Run and submit your code as often as you need. You also have five interviewer messages this session - want to talk through your approach, or are you ready to start coding?

You need to log in / sign up to run or submit.

Problem

PulseBoard wants to measure whether newly active users come back within 30 days of their first login. Write a SQL query to calculate 30-day retention by signup cohort date.

A user is considered retained if they have at least one feature usage event between 1 and 30 days after their first login date. Ignore usage on the same day as first login.

Requirements

  1. Find each user's first login date from the user_logins table.
  2. Join to feature_usage and determine whether the user had any usage event from first_login_date + 1 day through first_login_date + 30 days.
  3. Return one row per signup_date from the users table with:
    • signup_date
    • cohort_size
    • retained_users
    • retention_rate rounded to 4 decimal places
  4. Include cohorts even if retention is 0, and order results by signup_date ascending.

Schema

users
ColumnTypeDescription
user_idPKINTUnique user identifier
user_nameVARCHAR(100)User full name
signup_dateDATEDate the user signed up
plan_typeVARCHAR(20)Subscription plan at signup
user_logins
ColumnTypeDescription
login_idPKINTUnique login event identifier
user_idINTUser who logged in
login_dateDATEDate of the login event
device_typeVARCHAR(20)Device used for login
feature_usage
ColumnTypeDescription
usage_idPKINTUnique feature usage event identifier
user_idINTUser who used a feature
usage_dateDATEDate of feature usage
feature_nameVARCHAR(50)Name of the feature used
Tablesusersuser_loginsfeature_usage
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results