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
作者:弦断
出处:http://www.cnblogs.com/ucas/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。