Friend Requests I: Overall Acceptance Rate


  • 0

    Click here to see the full article post


  • 0
    X

    I tried the query in Sqlite, it returns 0. Not how MySQL handle a integer divide by integer.


  • 0
    L

    THERE IS NO NEED TO USE 5 SELECT ,

    SELECT ROUND(IFNULL(

    (SELECT COUNT(DISTINCT requester_id, accepter_id) FROM request_accepted) /

    (SELECT COUNT(DISTINCT sender_id, send_to_id) FROM friend_request )

       ,0)  ,2)   AS accept_rate

  • 0
    S

    In fact, we can go with only one select, but with join, that might be less effective:

    select IFNULL( ROUND (count(distinct requester_id, accepter_id) / count(distinct sender_id, send_to_id), 2), 0.00) as accept_rate
    from friend_request JOIN request_accepted;


Log in to reply
 

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