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
Rolling Retention with Window Functions
00:00
5 left

Rolling Retention with Window Functions

HardSQL · PostgreSQL

Problem

Lyft wants to measure whether riders who take a completed ride remain active. Write a PostgreSQL query that calculates rolling 30-day retention for active Lyft riders.

For each activity date from January 1 through January 4, 2024, an active rider is retained if the same rider completes at least one later ride within the following 30 days, including day 30 and excluding the original activity date.

Requirements

  1. Join rides to riders and include only riders whose account is active and rides whose status is completed.
  2. Use a window function to deduplicate multiple rides by the same rider on the same date.
  3. Return each activity date, active rider count, retained rider count, and retention rate as a percentage, rounded to two decimals.
  4. Order the results chronologically. Do not count a rider more than once in either metric.

Schema

riders
ColumnTypeDescription
rider_idPKINTUnique Lyft rider identifier
rider_nameVARCHAR(100)Rider display name
account_statusVARCHAR(20)Current rider account status
rides
ColumnTypeDescription
ride_idPKINTUnique ride identifier
rider_idINTRider who took the ride
ride_dateDATECalendar date of the ride
ride_statusVARCHAR(20)Ride outcome
completed_atTIMESTAMPTimestamp when the ride completed
Tablesridersrides
Interviewer

Your question is Rolling Retention with Window Functions. 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.