bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 262. Trips and Users

262. Trips and Users

Leetcode Solutions

Calculating Cancellation Rate Using SQL Joins and Aggregation

  1. Perform a LEFT JOIN of the Trips table with the Users table on client_id to get client information.
  2. Perform another LEFT JOIN of the result with the Users table on driver_id to get driver information.
  3. Use a WHERE clause to filter out trips with banned clients or drivers and to consider only trips within the specified date range.
  4. Group the results by the request_at date.
  5. Calculate the cancellation rate by dividing the count of cancelled trips by the total number of trips for each day, and round the result to two decimal places.
  6. Select the request_at date and the calculated cancellation rate in the final output.
erDiagram
    Users {
        int users_id
        enum banned
        enum role
    }
    Trips {
        int id
        int client_id
        int driver_id
        int city_id
        enum status
        date request_at
    }
    Users ||--o{ Trips : "client_id"
    Users ||--o{ Trips : "driver_id"

Calculating Cancellation Rate Using Subqueries and Conditional Aggregation

Ask Question

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

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...