Skip to content

602. Friend Requests II: Who Has the Most Friends 👍

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
WITH
  AllIds AS (
    SELECT requester_id AS id FROM RequestAccepted
    UNION ALL
    SELECT accepter_id FROM RequestAccepted
  )
SELECT
  id,
  COUNT(*) AS num
FROM AllIds
GROUP BY 1
ORDER BY 2 DESC
LIMIT 1;