https://leetcode-cn.com/problems/leetcodify-similar-friends/
1919.pngselect 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
网友评论