Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Rider Percentile by Distance

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

Welcome to the SQL screen.

The question is on your right: Top Rider Percentile by Distance. Read through the requirements and the two 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

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