sqlGirl

sql-行程和客户

题目链接:https://leetcode-cn.com/problems/trips-and-users/

我的答案:

select Request_at 'Day',round(avg(Status!='completed'),2) 'Cancellation Rate'
from trips t join users u1 on (t.client_id=u1.users_id and u1.banned='no')
join users u2 on (t.driver_id=u2.users_id and u2.banned='no')
where Request_at between '2013-10-01' and '2013-10-03'
group by request_at
order by request_at;

注意的就是取消行程可以是用户取消,也可以是司机取消。Users表中既有用户id又有司机id。需要按日期分组求平均值即可。

sql-行程和客户已关闭评论