Sub Query - very esay to understand


  • 0
    select Request_at Day, ROUND(SUM(IF(status = 'completed', 0, 1)) / COUNT(*), 2) 'Cancellation Rate'
    from (select * from trips,users where users.Banned = 'No' and users.Users_Id=trips.Client_Id) as t
    where request_at BETWEEN '2013-10-01' AND '2013-10-03'
    group by t.Request_at;
    

    Talk about it:
    First, find a table that with out banned, just like:

    select * from trips,users where users.Banned = 'No' and users.Users_Id=trips.Client_Id;
    

    Then, in this table, find the rate that uncompleted, just like:

    ROUND(SUM(IF(status = 'completed', 0, 1)) / COUNT(*), 2)
    

    End:)


Log in to reply
 

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