Leetcode 1919 兴趣相同的朋友

2021-11-28  本文已影响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
上一篇下一篇

猜你喜欢

热点阅读