프로그래밍연습/SQL

[SQL]trips-and-users

Q_jihe 2023. 8. 18. 14:26

https://leetcode.com/problems/trips-and-users

select 
    t.request_at as Day
    , round(1.00*count(distinct(if(t.status like 'cancel%', t.id, null)))/count(distinct t.id), 2) as 'Cancellation Rate'
from trips t
left join users u on t.client_id = u.users_id
    and u.role = 'client' and u.banned = 'No'
left join users u2 on t.driver_id = u2.users_id 
    and u2.role = 'driver' and u2.banned = 'No'
where u.users_id is not null and u2.users_id is not null
    and t.request_at between date('2013-10-01') and date('2013-10-03')
group by 1