← Interview questions
Lyft logo

Underperforming Drivers

Lyft·medium·SQL

Find drivers whose average completed ride duration is more than 20% below the average for their city. Return driver_id, city, the driver's average duration in minutes, the city average, and the percentage difference. Only count rides with status 'completed'. Round all numeric values to 2 decimal places, ordered by percentage difference ascending.

Schema

drivers
driver_idINTEGER
nameVARCHAR
cityVARCHAR
joined_dateDATE
rides
ride_idINTEGER
driver_idINTEGER
statusVARCHAR
start_timeTIMESTAMP
end_timeTIMESTAMP
status values: 'completed', 'cancelled'

Target output

Target output
driver_idcitydriver_avg_minscity_avg_minspct_difference
14Chicago8.0012-33.33
22Austin8.5011-22.73
Querydrivers, rides
Cmd+Enterto runLoading...
Output

Loading sample data...