题解 | #网易云音乐推荐(网易校招笔试真题)#
网易云音乐推荐(网易校招笔试真题)
http://www.nowcoder.com/practice/048ed413ac0e4cf4a774b906fc87e0e7
先查找user_id=1关注的用户和他喜欢的music_id
select follower_id from follow where user_id=1
select music_id from music_likes where user_id=1
再将用户喜欢的music_id和music_name表连接起来
select *
from music_likes ml
left join music m
on ml.music_id=m.id
最后查从user_id=1 关注的用户喜欢的music中除掉1用户喜欢的音乐
整合:
select distinct music_name
from music_likes ml
left join music m
on ml.music_id=m.id
where user_id in (select follower_id from follow where user_id=1)
and music_id not in (select music_id from music_likes where user_id=1)
order by m.id