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

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

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

# select  distinct c.music_name 
# from follow a inner join music_likes b on a.follower_id=b.user_id inner join music c on c.id=b.music_id
# where a.user_id=1 and b.music_id not in (select music_id from music_likes where user_id=1)
# order by c.id
# 当distinct和order by 同时使用会报错,因为先执行distinct再执行order by,当我们没法对去重前的数据进行排序,可以通过子查询进行解决
select music_name from 
(select  distinct c.music_name,c.id
from follow a inner join music_likes b on a.follower_id=b.user_id inner join music c on c.id=b.music_id
where a.user_id=1 and b.music_id not in (select music_id from music_likes where user_id=1)) t
order by id

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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