Solution Using UNION, ORDER BY and LIMIT


  • 0
    I
    # Write your MySQL query statement below
    SELECT
        u1.id,
        u1.num
    FROM (
        SELECT 
            u2.id,
            (
                SELECT COUNT(r.requester_id)
                FROM request_accepted r
                WHERE r.requester_id = u2.id
            ) + (
                SELECT COUNT(r.accepter_id)
                FROM request_accepted r
                WHERE r.accepter_id = u2.id
            ) AS "num"
        FROM ((
            SELECT requester_id AS "id"
            FROM request_accepted 
        ) UNION (
            SELECT accepter_id AS "id"
            FROM request_accepted
        )) u2
    ) u1
    ORDER BY u1.num DESC
    LIMIT 1;
    

Log in to reply
 

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