1、题目描述
来源:力扣(LeetCode)
2、解题思路
1# 计算取消数量:sum(case when `Status` like 'cancelled_by_%' then 1 else 0 end)
;
与总数的比值作为取消率count(Id)
;用round()
函数,取2为小数
2# Users u
作为乘客表,Users u1
作为司机表,与Trips t
表联查
司机和乘客Banned='No'
,Trips t
时间限制:t.Request_at between '2013-10-01' and '2013-10-03'
3、提交记录
select Request_at as Day,round(sum(case when `Status` like 'cancelled_by_%' then 1 else 0 end) / count(Id),2) as 'Cancellation Rate'
from Trips t join Users u on t.Client_Id=u.Users_Id join Users u1 on t.Driver_Id=u1.Users_Id
where u.Banned='No' and u1.Banned='No' and t.Request_at between '2013-10-01' and '2013-10-03'
group by 1
order by 1