SQL Lab – SmartCab Taxi Service
Section: D8
This lab focuses on real-world SQL queries using a ride-hailing scenario to practice
aggregate functions, nested and correlated queries, set operations, and data filtering.
Scenario: SmartCab – Ride & Driver Analysis
SmartCab is a popular ride-hailing service operating in multiple cities. The company
maintains data on:
- Drivers and their city
- Rides (including fare and customer ratings)
- Complaints made by passengers
You are hired as a data analyst to write SQL queries that help analyze performance,
customer satisfaction, and operational insights.
Table Structures
1. Drivers
DriverID – Unique identifier for each driver
Name – Driver's full name
City – City where the driver is based
2. Rides
RideID – Unique ride identifier
DriverID – Refers to the driver who did the ride
RideDate – Date of the ride
Fare – Fare earned in the ride (decimal)
Rating – Customer rating out of 5 (float)
3. Complaints
ComplaintID – Unique ID for each complaint
DriverID – Driver involved in the complaint
ComplaintText – Text/description of the complaint
ComplaintDate – Date the complaint was filed
Lab Questions
Q1. Display the total fare and average rating earned by each driver. (Columns: DriverID,
TotalFare, AverageRating)
Q2. Show the average fare earned per city. (Columns: City, AverageFare)
Q3. List the names of drivers who earned more than the overall average fare across all rides.
Q4. List drivers who have at least one ride where the rating was higher than their own
average rating.
Q5. Retrieve names of all drivers who are either based in Lahore or have at least one
complaint filed against them.
Q6. Display names of drivers who have at least one ride with a rating below 3 AND have a
complaint filed.
Q7. Find the names of drivers who received the highest individual fare in any ride.
Q8. List drivers who have received more than one complaint.
Q9. Show the total fare collected each day. (Columns: RideDate, TotalFare)
Q10. Find the top 3 drivers with the highest average rating (among those who have
completed at least 2 rides).