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
网友评论