Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Rider Percentile by Distance

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

Your question is Top Rider Percentile by Distance. 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

You are given Waymo rider trip data and rider profile data. Write a PostgreSQL query to identify the top 5% of riders by total distance traveled and return each qualifying rider with their average trip duration in minutes. Treat total distance as the sum of all completed trip distances per rider, and average duration as the average of completed trip durations only. If the 5% cutoff falls between riders, include riders whose percentile rank places them in the top 5%.

Schema

waymo_riders
ColumnTypeDescription
rider_idPKINTUnique rider identifier
rider_nameVARCHAR(100)Rider full name
cityVARCHAR(50)Primary city for the rider
signup_dateDATEDate the rider signed up
waymo_trips
ColumnTypeDescription
trip_idPKINTUnique trip identifier
rider_idINTRider who took the trip
trip_dateDATEDate of the trip
distance_milesDECIMAL(8,2)Distance traveled in miles
duration_minutesINTTrip duration in minutes
trip_statusVARCHAR(20)Trip completion status
Tableswaymo_riderswaymo_trips
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results