题解 | #获得积分最多的人(一)#
网易云音乐推荐(网易校招笔试真题)
http://www.nowcoder.com/practice/048ed413ac0e4cf4a774b906fc87e0e7
select music_name from music where id in
(
select music_id from music_likes left join follow on music_likes.user_id = follow.follower_id where follow.user_id=1
) and id not in
(select music_id from music_likes where user_id=1)
order by id
思路:
1.求出user_id为1的人喜欢的音乐id
select music_id from music_likes where user_id=1
2.求出user_id为1的人关注的人喜欢的音乐id,将music_likes和follow表join连接即可
select music_id from music_likes left join follow on music_likes.user_id = follow.follower_id
where follow.user_id=1
3.从music中筛选出来已关注人喜欢的音乐,并剔除自己喜欢的音乐
select music_id from music_likes left join follow on music_likes.user_id = follow.follower_id
where follow.user_id=1
order by id