๐ Hopper Company Queries I - Monthly Business Analytics
You're a data analyst at Hopper, a ride-sharing company that's tracking their business growth throughout 2020. Your task is to generate a comprehensive monthly report that shows two key metrics:
- Active Drivers: The cumulative number of drivers who have joined the company by the end of each month
- Accepted Rides: The total number of rides that were successfully matched with drivers each month
You have access to three database tables:
Rides Table: Contains all ride requests (both accepted and rejected)
AcceptedRides Table: Contains details only for rides that were successfully matched
The challenge is to handle the cumulative nature of driver counts (once a driver joins, they remain active) while calculating monthly ride statistics. You need to generate results for all 12 months of 2020, even if some months have zero activity.
Goal: Return a report ordered by month (1=January, 2=February, etc.) showing month, active_drivers, and accepted_rides for each month in 2020.
Input & Output
Visualization
Time & Space Complexity
Where n is drivers and m is rides. Each table is scanned once with efficient aggregation.
Space for 12 months plus intermediate aggregation results
Constraints
- 1 โค Drivers.driver_id โค 103
- 1980-01-01 โค Drivers.join_date โค 2020-12-31
- 1 โค Rides.ride_id โค 105
- 1 โค Rides.user_id โค 104
- 2020-01-01 โค Rides.requested_at โค 2020-12-31
- AcceptedRides.ride_id is guaranteed to exist in Rides table
- Report must include all 12 months of 2020, even with zero activity