Skip to content

Latest commit

 

History

History
15 lines (14 loc) · 559 Bytes

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

File metadata and controls

15 lines (14 loc) · 559 Bytes

602. Friend Requests II: Who Has the Most Friends

Question Link

Solution

# Write your MySQL query statement below
select r.id, r.num from (
  select a.requester_id id, sum(a.cnt1) num from (
    select requester_id, count(requester_id) cnt1 from RequestAccepted group by requester_id
    union all
    select accepter_id, count(accepter_id) cnt1 from RequestAccepted group by accepter_id
  ) a group by a.requester_id order by num desc
) r
having r.num=max(r.num)