美文网首页
Leetcode 1919 兴趣相同的朋友

Leetcode 1919 兴趣相同的朋友

作者: 七齐起器 | 来源:发表于2021-11-28 23:26 被阅读0次

    https://leetcode-cn.com/problems/leetcodify-similar-friends/

    1919.png
    select distinct b.user1_id,b.user2_id from (
        select a.* from (
            select day, user_id,count(distinct song_id) from Listens group by day, user_id having count(distinct song_id)>=3
            )b left join Listens a on a.day=b.day and a.user_id=b.user_id 
        where b.day is not null and b.user_id is not null 
    )a left join Friendship b on a.user_id=b.user1_id 
       left join Listens c on b.user2_id=c.user_id and a.day=c.day and a.song_id=c.song_id
       where b.user1_id is not null 
       and c.user_id is not null 
       group by b.user1_id,b.user2_id,a.day 
       having count(distinct a.song_id)>=3
    

    相关文章

      网友评论

          本文标题:Leetcode 1919 兴趣相同的朋友

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