笨比解法 我是笨比
select distinct sums.request_at as `Day`, ifnull(convert(cancle.counts/sums.counts,decimal(15,2)),0.00) as `Cancellation Rate` from
(select count(*) as counts,ppt.request_at from
(select tc.*,uc.banned as driverBan from
(select t.*,u.banned as clientBan from Trips t left join Users u
on
t.client_id=u.users_id) as tc left join Users uc
on
tc.driver_id=uc.users_id) as ppt
where ppt.driverBan='No' and ppt.clientBan='No' and ppt.request_at between '2013-10-01' and
'2013-10-03' and ppt.status!='completed' group by ppt.request_at) as cancle
right join
(select count(*) as counts,ppt.request_at from
(select tc.*,uc.banned as driverBan from
(select t.*,u.banned as clientBan from Trips t left join Users u
on
t.client_id=u.users_id) as tc left join Users uc
on
tc.driver_id=uc.users_id) as ppt
where ppt.driverBan='No' and ppt.clientBan='No' and ppt.request_at between '2013-10-01' and
'2013-10-03' group by ppt.request_at) as sums
on sums.request_at=cancle.request_at