[코드카타] SQL 56 Friend Requests Ⅱ: Who Has the Most Friends

Data_Student·2024년 12월 3일
0

코드카타

목록 보기
65/82

[코드카타] SQL 56 Friend Requests Ⅱ: Who Has the Most Friends

56 Friend Requests Ⅱ: Who Has the Most Friends
https://leetcode.com/problems/friend-requests-ii-who-has-the-most-friends/

Write a solution to find the people who have the most friends 
and the most friends number.
The test cases are generated so that only one person has the most friends.
with temp as (
    select requester_id id 
    from RequestAccepted
    union all
    select accepter_id id
    from RequestAccepted
)
select id, count(*) num
from temp
group by 1
order by 2 desc limit 1
union all을 통한 수직결합으로
requester_id와 accepter_id를 id라는 컬럼에 통합
그후 id와 num으로 추출
num기준으로 가장 많은 연관성이 있는 사람을 찾기

0개의 댓글