Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Drivers by Monthly Rating

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

Your question is Top Drivers by Monthly Rating. 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

Uber wants a monthly leaderboard of driver quality. Write a PostgreSQL query that returns the top 10 drivers by average rating for the last month, using a fixed reporting date of 2026-06-01.

Requirements

  1. Only include rides with ride_status = 'completed'.
  2. Use the last-month window starting on 2026-05-01 and ending before 2026-06-01.
  3. Exclude completed rides where rating is NULL.
  4. Return driver_name, avg_rating rounded to 2 decimals, and completed_rides.
  5. Sort by avg_rating descending, then completed_rides descending, then driver_name ascending.
  6. Return at most 10 rows.

Input Tables

drivers

columntypedescription
driver_idINTUnique driver identifier
driver_nameVARCHAR(100)Driver display name

rides

columntypedescription
ride_idINTUnique ride identifier
driver_idINTDriver assigned to the ride
ride_dateDATEDate of the ride
ratingDECIMAL(3,2)Passenger rating for the ride
ride_statusVARCHAR(20)Ride status such as completed or canceled

Schema

drivers
ColumnTypeDescription
driver_idPKINTUnique driver identifier
driver_nameVARCHAR(100)Driver display name
rides
ColumnTypeDescription
ride_idPKINTUnique ride identifier
driver_idINTDriver assigned to the ride
ride_dateDATEDate of the ride
ratingDECIMAL(3,2)Passenger rating for the ride
ride_statusVARCHAR(20)Ride status such as completed or canceled
Tablesdriversrides
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results