262. Trips and Users

问题描述

解决方案

-- case when 的效率比if的效率高
-- select  Trips.Request_at as 'Day',
-- round(sum(case Trips.Status when 'completed' then 0 else 1 end)/sum(1),2) as 'Cancellation Rate' 

-- SELECT Trips.Request_at Day,
-- round(sum(if(status != 'completed', 1, 0)) / sum(1), 2) 'Cancellation Rate'

from  Trips   
join Users 
on  Trips.Client_Id =Users.Users_Id 
where  Users.Banned='No'  and Trips.Request_at between '2013-10-01' and '2013-10-03'  
group by   Trips.Request_at 

posted @ 2016-08-11 16:16  弦断  阅读(129)  评论(0编辑  收藏  举报