美文网首页
Leetcode 1917. Leetcodify Friend

Leetcode 1917. Leetcodify Friend

作者: 七齐起器 | 来源:发表于2021-11-27 17:27 被阅读0次
    1917.png
    select distinct a.user_id,a.recommended_id
    from(
        select user_id,recommended_id,max(a.rn)rn from(
        select distinct row_number() over(partition by a.user_id,b.user_id,a.day)rn
        ,a.user_id user_id
        ,b.user_id recommended_id
        ,a.song_id
        ,a.day
        from (select distinct * from Listens) a left join (select distinct * from Listens) b on a.song_id=b.song_id and a.day=b.day and a.user_id!=b.user_id 
        where b.song_id is not null and b.day is not null and b.user_id  is not null 
        )a group by user_id,recommended_id
    )a left join Friendship b on (a.user_id=b.user1_id and a.recommended_id=b.user2_id) or (a.user_id=b.user2_id and a.recommended_id=b.user1_id)
    where b.user1_id is null and b.user2_id is null and a.rn>=3
    

    相关文章

      网友评论

          本文标题:Leetcode 1917. Leetcodify Friend

          本文链接:https://www.haomeiwen.com/subject/kfrxxrtx.html