Skip to content

Commit 2849ba9

Browse files
committed
Update trips-and-users.sql
1 parent dd4cb7f commit 2849ba9

1 file changed

Lines changed: 41 additions & 1 deletion

File tree

MySQL/trips-and-users.sql

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,46 @@
11
# Time: O((t * u) + tlogt)
22
# Space: O(t)
3-
3+
#
4+
# The Trips table holds all taxi trips. Each trip has a unique Id, while Client_Id and Driver_Id are both foreign keys to the Users_Id at the Users table. Status is an ENUM type of (‘completed’, ‘cancelled_by_driver’, ‘cancelled_by_client’).
5+
#
6+
# +----+-----------+-----------+---------+--------------------+----------+
7+
# | Id | Client_Id | Driver_Id | City_Id | Status |Request_at|
8+
# +----+-----------+-----------+---------+--------------------+----------+
9+
# | 1 | 1 | 10 | 1 | completed |2013-10-01|
10+
# | 2 | 2 | 11 | 1 | cancelled_by_driver|2013-10-01|
11+
# | 3 | 3 | 12 | 6 | completed |2013-10-01|
12+
# | 4 | 4 | 13 | 6 | cancelled_by_client|2013-10-01|
13+
# | 5 | 1 | 10 | 1 | completed |2013-10-02|
14+
# | 6 | 2 | 11 | 6 | completed |2013-10-02|
15+
# | 7 | 3 | 12 | 6 | completed |2013-10-02|
16+
# | 8 | 2 | 12 | 12 | completed |2013-10-03|
17+
# | 9 | 3 | 10 | 12 | completed |2013-10-03|
18+
# | 10 | 4 | 13 | 12 | cancelled_by_driver|2013-10-03|
19+
# +----+-----------+-----------+---------+--------------------+----------+
20+
# The Users table holds all users. Each user has an unique Users_Id, and Role is an ENUM type of (‘client’, ‘driver’, ‘partner’).
21+
#
22+
# +----------+--------+--------+
23+
# | Users_Id | Banned | Role |
24+
# +----------+--------+--------+
25+
# | 1 | No | client |
26+
# | 2 | Yes | client |
27+
# | 3 | No | client |
28+
# | 4 | No | client |
29+
# | 10 | No | driver |
30+
# | 11 | No | driver |
31+
# | 12 | No | driver |
32+
# | 13 | No | driver |
33+
# +----------+--------+--------+
34+
# Write a SQL query to find the cancellation rate of requests made by unbanned clients between Oct 1, 2013 and Oct 3, 2013. For the above tables, your SQL query should return the following rows with the cancellation rate being rounded to two decimal places.
35+
#
36+
# +------------+-------------------+
37+
# | Day | Cancellation Rate |
38+
# +------------+-------------------+
39+
# | 2013-10-01 | 0.33 |
40+
# | 2013-10-02 | 0.00 |
41+
# | 2013-10-03 | 0.50 |
42+
# +------------+-------------------+
43+
#
444
select
545
t.Request_at Day,
646
round(sum(case when t.Status like 'cancelled_%' then 1 else 0 end) / count(*), 2) Rate

0 commit comments

Comments
 (0)