2022-03-27 18:35:17 +08:00
< p > Table: < code > Trips< / code > < / p >
< pre >
+-------------+----------+
| Column Name | Type |
+-------------+----------+
| id | int |
| client_id | int |
| driver_id | int |
| city_id | int |
| status | enum |
| request_at | date |
+-------------+----------+
2023-12-09 18:42:21 +08:00
id is the primary key (column with unique values) for this table.
2022-03-27 18:35:17 +08:00
The table holds all taxi trips. Each trip has a unique id, while client_id and driver_id are foreign keys to the users_id at the Users table.
2023-12-09 18:42:21 +08:00
Status is an ENUM (category) type of (' completed' , ' cancelled_by_driver' , ' cancelled_by_client' ).
2022-03-27 18:35:17 +08:00
< / pre >
< p > < / p >
< p > Table: < code > Users< / code > < / p >
< pre >
+-------------+----------+
| Column Name | Type |
+-------------+----------+
| users_id | int |
| banned | enum |
| role | enum |
+-------------+----------+
2023-12-09 18:42:21 +08:00
users_id is the primary key (column with unique values) for this table.
2022-03-27 18:35:17 +08:00
The table holds all users. Each user has a unique users_id, and role is an ENUM type of (' client' , ' driver' , ' partner' ).
2023-12-09 18:42:21 +08:00
banned is an ENUM (category) type of (' Yes' , ' No' ).
2022-03-27 18:35:17 +08:00
< / pre >
< p > < / p >
< p > The < strong > cancellation rate< / strong > is computed by dividing the number of canceled (by client or driver) requests with unbanned users by the total number of requests with unbanned users on that day.< / p >
2023-12-09 18:42:21 +08:00
< p > Write a solution to find the < strong > cancellation rate< / strong > of requests with unbanned users (< strong > both client and driver must not be banned< / strong > ) each day between < code > " 2013-10-01" < / code > and < code > " 2013-10-03" < / code > . Round < code > Cancellation Rate< / code > to < strong > two decimal< / strong > points.< / p >
2022-03-27 18:35:17 +08:00
< p > Return the result table in < strong > any order< / strong > .< / p >
2023-12-09 18:42:21 +08:00
< p > The result format is in the following example.< / p >
2022-03-27 18:35:17 +08:00
< p > < / p >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 1:< / strong > < / p >
2022-03-27 18:35:17 +08:00
< pre >
< strong > Input:< / strong >
Trips table:
+----+-----------+-----------+---------+---------------------+------------+
| id | client_id | driver_id | city_id | status | request_at |
+----+-----------+-----------+---------+---------------------+------------+
| 1 | 1 | 10 | 1 | completed | 2013-10-01 |
| 2 | 2 | 11 | 1 | cancelled_by_driver | 2013-10-01 |
| 3 | 3 | 12 | 6 | completed | 2013-10-01 |
| 4 | 4 | 13 | 6 | cancelled_by_client | 2013-10-01 |
| 5 | 1 | 10 | 1 | completed | 2013-10-02 |
| 6 | 2 | 11 | 6 | completed | 2013-10-02 |
| 7 | 3 | 12 | 6 | completed | 2013-10-02 |
| 8 | 2 | 12 | 12 | completed | 2013-10-03 |
| 9 | 3 | 10 | 12 | completed | 2013-10-03 |
| 10 | 4 | 13 | 12 | cancelled_by_driver | 2013-10-03 |
+----+-----------+-----------+---------+---------------------+------------+
Users table:
+----------+--------+--------+
| users_id | banned | role |
+----------+--------+--------+
| 1 | No | client |
| 2 | Yes | client |
| 3 | No | client |
| 4 | No | client |
| 10 | No | driver |
| 11 | No | driver |
| 12 | No | driver |
| 13 | No | driver |
+----------+--------+--------+
< strong > Output:< / strong >
+------------+-------------------+
| Day | Cancellation Rate |
+------------+-------------------+
| 2013-10-01 | 0.33 |
| 2013-10-02 | 0.00 |
| 2013-10-03 | 0.50 |
+------------+-------------------+
< strong > Explanation:< / strong >
On 2013-10-01:
- There were 4 requests in total, 2 of which were canceled.
- However, the request with Id=2 was made by a banned client (User_Id=2), so it is ignored in the calculation.
- Hence there are 3 unbanned requests in total, 1 of which was canceled.
- The Cancellation Rate is (1 / 3) = 0.33
On 2013-10-02:
- There were 3 requests in total, 0 of which were canceled.
- The request with Id=6 was made by a banned client, so it is ignored.
- Hence there are 2 unbanned requests in total, 0 of which were canceled.
- The Cancellation Rate is (0 / 2) = 0.00
On 2013-10-03:
- There were 3 requests in total, 1 of which was canceled.
- The request with Id=8 was made by a banned client, so it is ignored.
- Hence there are 2 unbanned request in total, 1 of which were canceled.
- The Cancellation Rate is (1 / 2) = 0.50
< / pre >