Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

7-Day Rider Retention in NYC

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

Your question is 7-Day Rider Retention in NYC. 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

RideNow wants to measure early rider retention for new NYC riders. Write a SQL query to calculate the 7-day rolling retention rate by signup date cohort.

A rider is considered retained if they complete at least one trip in NYC between day 1 and day 7 after signup, inclusive. The signup day itself does not count.

Requirements

  1. Consider only riders whose signup_city is 'NYC'.
  2. Build daily signup cohorts using signup_date from the riders table.
  3. For each cohort date, calculate:
    • total new riders
    • retained riders
    • retention rate = retained riders / total new riders
  4. Return one row per signup_date, ordered by signup_date ascending.
  5. Ignore trips outside NYC when determining retention.
  6. Count each rider at most once in the retained population, even if they took multiple qualifying trips.

Schema

riders
ColumnTypeDescription
rider_idPKINTUnique rider identifier
signup_dateDATEDate the rider signed up
signup_cityVARCHAR(50)City where the rider signed up
referral_codeVARCHAR(20)Optional referral code used at signup
trips
ColumnTypeDescription
trip_idPKINTUnique trip identifier
rider_idINTRider who completed the trip
trip_dateDATETrip completion date
cityVARCHAR(50)City where the trip occurred
fare_amountNUMERIC(10,2)Fare paid for the trip
Tablesriderstrips
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results