LeetCode 262:Trips and Users
【Description】
Write a SQL query to find the cancellation rate of requests made by unbanned users (both client and driver must be unbanned) between “2013-10-01” and “2013-10-03”.
The cancellation rate is computed by dividing the number of canceled (by client or driver) requests made by unbanned users by the total number of requests made by unbanned users.
Return the result table in any order. Round Cancellation Rate to two decimal points.
The query result format is in the following example:
【Solution】
Personal solution:
with temp as (
select *
from trips
where client_id not in (select users_id from users where banned = "yes")
and request_at between "2013-10-01" and "2013-10-03"
)
select request_at as "Day",
round(sum(if (status like "cancelled_by_%",1,0))/count(1),2) as "Cancellation Rate"
from temp
group by request_at