#240

Ride-Sharing KPI Analysis

MEDIUMData ModelingPOSTGRESQL

Problem Description

You are a data engineer building a **driver performance reporting pipeline** for a ride-sharing platform. The analytics team needs a dashboard table that summarises, per driver, the average time riders wait and the driver's overall ride completion rate. **Schema:** - `drivers`: one row per driver; includes `driver_id`, `driver_name`, `vehicle_type`, `status`, `rating`, `signup_date`. - `rides`: one row per ride request; includes `ride_id`, `driver_id`, `rider_id`, `request_time`, `pickup_time`, `dropoff_time`, `fare_amount`, `status`. - `status` is one of `'completed'`, `'cancelled'`, `'in_progress'`. - `pickup_time` is `NULL` for cancelled rides. **Key Rules:** - **Wait time** = minutes elapsed between `request_time` and `pickup_time`, computed only for `'completed'` rides (cancelled rides have no pickup, so exclude them from the average). - **Completion rate** = `(completed rides / total rides) * 100`, rounded to 2 decimal places. - **Total revenue** = sum of `fare_amount` for `'completed'` rides only. - Include every driver who has at least one ride record; return `NULL` for `avg_wait_minutes` if the driver has zero completed rides. - Order results by `driver_id` ascending. **Output:** | driver_id | driver_name | avg_wait_minutes | completion_rate | completed_rides | total_revenue | |-----------|-------------|-----------------|----------------|----------------|--------------| | (integer) | (string) | (decimal, 2dp) | (%, 2dp) | (integer) | (decimal) |

Topics

date functions

Asked at Companies

oracle

Solve This Problem

Sign up to access the interactive code editor, run test cases, view the editorial, and get AI-powered feedback on your solution.

Start Solving →