题解 | #网易云音乐推荐(网易校招笔试真题)#
网易云音乐推荐(网易校招笔试真题)
http://www.nowcoder.com/practice/048ed413ac0e4cf4a774b906fc87e0e7
select DISTINCT music_name from
(select user_id , follower_id from follow where user_id = 1 ) a,
music_likes ml , music m
where a.follower_id = ml.user_id
and ml.music_id = m.id
and ml.music_id not in (
select ml.music_id from follow f,music_likes ml
where f.user_id =1
and f.user_id = ml.user_id
)
order by music_id
字段有点混乱,思路就是把user_id喜欢的music_id查出来,关注的user_id喜欢的music_id查出来,并去除user_id喜欢的music_id就可以,就是字段长的有点像,改了好久