Leetcode Problem 1645. Hopper Company Queries II

1645. Hopper Company Queries II

Leetcode Solutions

Calculating Working Drivers Percentage by Month

  1. Generate a list of months for the year 2020 using a recursive common table expression (CTE).
  2. Calculate the running total of active drivers for each month using a CTE that counts the number of drivers who have joined by the end of each month.
  3. Determine the number of working drivers for each month by counting the distinct driver IDs in the AcceptedRides table, joined with the Rides table, filtered by the year 2020.
  4. Calculate the working percentage for each month by dividing the number of working drivers by the total number of active drivers and multiplying by 100.
  5. Round the working percentage to two decimal places.
  6. Return the result table ordered by month in ascending order.
erDiagram
    Drivers {
        int driver_id
        date join_date
    }
    Rides {
        int ride_id
        int user_id
        date requested_at
    }
    AcceptedRides {
        int ride_id
        int driver_id
        int ride_distance
        int ride_duration
    }
    Drivers ||--o{ Rides : ""
    Rides ||--o{ AcceptedRides : ""

Using Window Functions for Running Totals

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...