Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
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 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
Build my plan
Calculate 30-Day User Retention
00:00
5 left

Calculate 30-Day User Retention

HardSQL · PostgreSQL

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
Interviewer

Your question is Calculate 30-Day User Retention. Start with the requirements and the three 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.