Months that generates a sequence of numbers from 1 to 12, representing the months of the year.Driver that selects driver_id and the month of joining from the Drivers table, filtering for drivers who joined on or before 2020.Ride that selects the month and ride_id from the AcceptedRides table joined with the Rides table, filtering for rides requested in 2020.Driver CTE with the Months CTE on the condition that the month of joining is less than or equal to the current month.Ride CTE with the result of the previous join on the month.COUNT DISTINCT function to calculate the number of active drivers and accepted rides for each month.
erDiagram
Drivers {
int driver_id PK
date join_date
}
Rides {
int ride_id PK
int user_id
date requested_at
}
AcceptedRides {
int ride_id PK
int driver_id
int ride_distance
int ride_duration
}
Drivers ||--o{ Rides : requests
Rides ||--o{ AcceptedRides : accepts