Sharing my solution

  • 9
    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

  • 0

    what does sum(1) do? does this really divide the cancelled trips by the total number?

  • 0

    to check and count the number row by row,
    add 1 if the row's status is 'completed',
    and the denominator should add 1 no mater what its status be

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.