RienSQL
TASK #215 · Hard · Cabify

Driver Utilization

Your brief
The driver_shifts table stores Cabify driver shifts: from shift_start to shift_end the driver is online. Time on rides is the interval from started_at to ended_at of completed rides (status = 'completed'). Utilization is the total time on rides divided by the total shift time, as a percentage.

Write a query that for every driver with at least one shift returns driver_name, online_hours (the total shift time in hours) and utilization_pct (the utilization); round both numbers to two decimals. A driver with shifts but no completed rides gets a utilization of 0. Sort by utilization_pct descending and, on ties, by driver_name alphabetically.
Expected columnsdriver_name online_hours utilization_pctCabify
SQL editor
SQLite
Ctrl / ⌘ + ↵
Result

Write a query and run it to see the results.

Schema
driversdriver_id, driver_name, city, car_model
driver_shiftsshift_id, driver_id, shift_start, shift_end
ridesride_id, driver_id, city, requested_at, status, started_at, ended_at, distance_km, surge_multiplier, fare_eur