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
Top 5% Drivers by City
00:00
5 left

Top 5% Drivers by City

HardSQL · PostgreSQL

Problem

Write a query to identify the top 5% of drivers in each city based on their monthly completed trips and ratings on Uber Drivers. Use completed trips only, and use average driver ratings as the secondary ranking criterion. Break ties consistently by driver ID.

Output

  1. One row per selected driver, city, and month
  2. Columns: city, monthly_month, driver_id, completed_trips, and average_rating
  3. Include only the top 5% within each city and month, ordered by city, monthly_month, completed trips descending, average rating descending, and driver ID

Schema

drivers
ColumnTypeDescription
driver_idPKINTUnique Uber Drivers driver identifier
cityVARCHAR(100)City where the driver operates
trips
ColumnTypeDescription
trip_idPKINTUnique trip identifier
driver_idINTDriver who completed or attempted the trip
completed_atTIMESTAMPTrip completion timestamp
statusVARCHAR(20)Trip lifecycle status
ratings
ColumnTypeDescription
rating_idPKINTUnique rating identifier
trip_idINTTrip receiving the rating
ratingDECIMAL(2,1)Passenger rating from 1.0 to 5.0
Tablesdriverstripsratings
Interviewer

Your question is Top 5% Drivers by City. 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.