Driver Trip Distance

ASKED IN INTERVIEW
4pts
Uber

Problem Statement

Uber operations teams are analyzing driver efficiency and trip patterns. To understand driver engagement, we need to calculate the average distance traveled per driver.

Write an SQL query to find the average distance for each driver, but only for trips that have been successfully completed.

Rules:

  • Only include trips where the status is completed.
  • Trips with statuses like cancelled by driver or cancelled by client must be excluded.
  • For drivers who have zero completed trips, they should not appear in the final output.
  • The average distance should be rounded to 2 decimal places.
  • Output columns: driver_name, avg_distance.
  • Results must be sorted by avg_distance in descending order.
Tests your understanding of
Filtering, Aggregation and Rounding

Input Tables

Drivers
driver_id(INTEGER)driver_name(VARCHAR)join_date(DATE)
1Michael2025-01-01
2Sarah2025-01-05
3Robert2025-01-10
4Daniel2025-01-15
5Jessica2025-02-01
6David2025-02-05
Trips
trip_id(INTEGER)driver_id(INTEGER)distance(DECIMAL)status(VARCHAR)
101112.5completed
10218completed
103215.2completed
10425cancelled_by_driver
105320completed
106110completed
Vehicles
vehicle_id(INTEGER)driver_id(INTEGER)make(VARCHAR)
5011Toyota
5022Honda
5033Tesla
5044Ford
5055Nissan
5066Hyundai

Expected Output

driver_name(VARCHAR)avg_distance(DECIMAL)
Robert20
Sarah15.2
Michael10.17

Tags

MediumASKED IN INTERVIEWFilteringAggregationRounding
10-15 min
68%

Hints