티스토리 뷰

https://leetcode.com/problems/friend-requests-ii-who-has-the-most-friends

 

Friend Requests II: Who Has the Most Friends - LeetCode

Can you solve this real interview question? Friend Requests II: Who Has the Most Friends - Table: RequestAccepted +----------------+---------+ | Column Name | Type | +----------------+---------+ | requester_id | int | | accepter_id | int | | accept_date |

leetcode.com

with base as (
    select
        requester_id as id
        , count(distinct accepter_id) cnt
    from RequestAccepted
    group by 1
    union all
    select
        accepter_id as id
        , count(distinct requester_id) cnt
    from RequestAccepted
    group by 1
)
, total as (
    select 
        id, sum(cnt) as num
    from base
    group by 1
)
select
    distinct id, num
from total
order by num desc
limit 1

'프로그래밍연습 > SQL' 카테고리의 다른 글

[SQL]confirmation-rate  (0) 2023.08.22
[SQL]exchange-seats  (0) 2023.08.21
[SQL]game-play-analysis-iv  (0) 2023.08.19
[SQL]human-traffic-of-stadium  (0) 2023.08.18
[SQL]trips-and-users  (0) 2023.08.18
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
글 보관함