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

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

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

select music_name from
(select distinct music_name,music_id
from follow join music_likes on follow.follower_id=music_likes.user_id join music on music_likes.music_id=music.id
where follow.user_id=1 ) as A
where music_name not in 
(select distinct music_name
from follow join music_likes on follow.user_id=music_likes.user_id join music on music_likes.music_id=music.id
where follow.user_id=1 )
order by music_id

分两个表进行分析:1、用户1喜欢的歌 2、用户1关注的人喜欢的歌。从表2中剔除表1里有的歌。

distinct函数会重新对表重新进行排序,所以可以在子查询中先去重,最后再用order by 进行排序。

全部评论

相关推荐

06-23 11:28
门头沟学院 Java
牛客91966197...:也有可能是点拒绝的时候自动弹的话术
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务