
Low-rated drivers
mediumLow-rated drivers
Uber SQL Interview Question
Uber's driver quality team reaches out to drivers whose riders keep giving them low ratings. Riders don't always leave a rating, and a single bad rating isn't enough to act on.
Find drivers with at least 2 rated rides and an average rating below 4. Return each driver's driver_name and their average rating as avg_rating, rounded to 2 decimal places. Rides without a rating don't count. Sort by avg_rating from lowest to highest, then by driver_name.
Asked of
- Data Analyst
- Business Analyst
- BI Analyst
- Product Analyst
- Analytics Engineer
ridesTable20 rows
| Column Name | Type |
|---|---|
| ride_id | BIGINT |
| driver_id | BIGINT |
| city | VARCHAR |
| requested_at | TIMESTAMP |
| fare | DOUBLE |
| rating | BIGINT |
driversTable10 rows
| Column Name | Type |
|---|---|
| driver_id | BIGINT |
| driver_name | VARCHAR |
| vehicle_type | VARCHAR |
| joined_date | DATE |
ridesExample Input
| ride_id | driver_id | city | requested_at | fare | rating |
|---|---|---|---|---|---|
| 7001 | 301 | Chicago | 2024-06-03 08:12:00 | 18.4 | 5 |
| 7002 | 302 | Chicago | 2024-06-03 08:40:00 | 32.1 | 4 |
| 7003 | 303 | Austin | 2024-06-03 09:05:00 | 54.75 | 5 |
| 7004 | 304 | Austin | 2024-06-03 09:30:00 | 12.9 | NULL |
| 7005 | 301 | Chicago | 2024-06-03 11:15:00 | 21.6 | 4 |
| 7006 | 305 | Seattle | 2024-06-03 12:02:00 | 87.2 | 5 |
| 7007 | 306 | Seattle | 2024-06-03 12:45:00 | 16.3 | 3 |
| 7008 | 302 | Chicago | 2024-06-03 13:20:00 | 27.8 | NULL |
| 7009 | 307 | Austin | 2024-06-03 14:10:00 | 41 | 4 |
| 7010 | 303 | Austin | 2024-06-03 15:35:00 | 63.25 | 5 |
| 7011 | 304 | Austin | 2024-06-03 16:05:00 | 14.2 | 2 |
| 7012 | 308 | Seattle | 2024-06-03 17:40:00 | 95.6 | 4 |
| 7013 | 305 | Seattle | 2024-06-03 18:15:00 | 76.4 | 5 |
| 7014 | 306 | Seattle | 2024-06-03 18:50:00 | 19.9 | 4 |
| 7015 | 301 | Chicago | 2024-06-03 19:30:00 | 23.1 | 5 |
| 7016 | 307 | Austin | 2024-06-03 20:05:00 | 38.6 | NULL |
| 7017 | 302 | Chicago | 2024-06-03 21:10:00 | 29.4 | 3 |
| 7018 | 308 | Seattle | 2024-06-03 22:00:00 | 102.3 | 5 |
| 7019 | 304 | Austin | 2024-06-03 22:40:00 | 11.75 | 3 |
| 7020 | 303 | Austin | 2024-06-03 23:15:00 | 58.9 | 4 |
driversExample Input
| driver_id | driver_name | vehicle_type | joined_date |
|---|---|---|---|
| 301 | Maya Patel | UberX | 2021-04-12 |
| 302 | Luis Romero | Comfort | 2020-09-01 |
| 303 | Grace Kim | UberXL | 2022-01-20 |
| 304 | Omar Haddad | UberX | 2023-03-08 |
| 305 | Elena Petrova | Black | 2019-11-15 |
| 306 | Sam Okoye | UberX | 2022-07-30 |
| 307 | Priya Iyer | Comfort | 2021-12-05 |
| 308 | Noah Fischer | Black | 2020-05-22 |
| 309 | Jordan Ellis | UberX | 2024-02-14 |
| 310 | Carmen Diaz | Black | 2023-10-01 |
Example Output
| driver_name | avg_rating |
|---|---|
| Omar Haddad | 2.5 |
| Luis Romero | 3.5 |
| Sam Okoye | 3.5 |
Explanation
Omar Haddad has three rides, but one has no rating, so only his ratings of 2 and 3 count, for an average of 2.5. Luis Romero and Sam Okoye both average 3.5, so they are sorted by name. Priya Iyer has only one rated ride, so she is left out.
The example above is a small slice of the data. Your query runs against the full tables.
Company
Uber
Difficulty
medium
Topic
aggregations
Language
SQL
Your query
Starting the SQL engine...