Leetcode - 602. Friend Requests II: Who Has the Most Friends

문제

Loading...
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

정답

SELECT Req.id, IFNULL(req_count, 0) + IFNULL(acc_count,0) AS num
FROM
(SELECT requester_id AS id, COUNT(requester_id) AS req_count
FROM RequestAccepted
GROUP BY requester_id) AS Req
LEFT JOIN
(SELECT accepter_id AS id, COUNT(accepter_id) AS acc_count
FROM RequestAccepted
GROUP BY accepter_id) AS Acc
ON Req.id = Acc.id
ORDER BY num DESC
LIMIT 1