Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

SQL Hard Question Failing 1 case

Status
Not open for further replies.

Risso

Newbie level 5
Joined
Jan 31, 2023
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
83
I am having difficulty passing all of the test cases when preparing for a data science interview. My code is only successful in some of the tests.
Can someone help explain why my code doesn't work for this question.

Here is the code:
Code:
# total rides by unbanned users by day
with total_rides as (SELECT t.request_at as day,
count(1) as total_rides
from trips t  join
users u on t.client_id = u.users_id and u.banned = 'No' and request_at between '2013-10-01' and '2013-10-03'
group by 1),

# cancelled rides by unbanned users by day
cancelled_rides as (
SELECT t.request_at as day,
count(1) as cancelled_rides
from trips t join
users u on t.client_id = u.users_id 
where t.status like 'cancelled%'and u.banned = 'No' and request_at between '2013-10-01' and '2013-10-03'
group by 1
),

combined as(select tr.day, tr.total_rides as total_rides, cr.cancelled_rides as cancelled_rides  from cancelled_rides cr
right join total_rides tr on cr.day = tr.day)

select day, case when cancelled_rides is NULL then 0
else round(cancelled_rides/total_rides,2) end as "cancellation rate"
from combined

Screenshot (320).png
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top