题解 | #网易云音乐推荐(网易校招笔试真题)#

网易云音乐推荐(网易校招笔试真题)

https://www.nowcoder.com/practice/048ed413ac0e4cf4a774b906fc87e0e7

select music_name from music where id in (select music_id from music_likes 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) )

1.首先查询在follow 表中用户 music_id 时,他的关注人的follower_id,

select follower_id from follow where user_id=1

2.在music_likes表中用户user_id 是follower_id ,查询出music_id,并且限定music_id 不是user_id=1的music_id

#用户user_id 是follower_id

select music_id from music_likes where user_id in (select follower_id from follow where user_id=1)

#并且限定music_id 不是user_id=1的music_id

music_id not in (select music_id from music_likes where user_id=1) )

**推荐其关注的人喜欢的音乐。不要推荐该用户已经喜欢的音乐,

总的来说就是select music_id from music_likes 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)

3.最后在表music中查询music_name

select music_name from music where id in (select music_id from music_likes 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) )

全部评论

相关推荐

10-31 14:54
已编辑
门头沟学院 算法工程师
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务