#115. [LeetCode / MySQL] 602. Friend Requests II: Who Has the Most Friends

문제

 

 

입력 코드

WITH base AS (SELECT requester_id AS id FROM RequestAccepted
UNION ALL
SELECT accepter_id AS id FROM RequestAccepted)

SELECT id, COUNT(*) AS num 
FROM base 
GROUP BY 1 
ORDER BY 2 DESC
LIMIT 1

 

 

코드 설명

#UNION #UNION ALL #SELECT #COUNT #GROUP BY #ORDER BY #DESC #LIMIT

 

 

문제 출처

https://leetcode.com/problems/friend-requests-ii-who-has-the-most-friends/description/?envType=study-plan-v2&envId=top-sql-50