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

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

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

/*
select follower_id
from follow
where user_id = 1;

select music_id
from music_likes as ml
where user_id = 1;

select music_id
from music_likes as ml
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);
*/
select music_name
from music
where id in (
    select music_id
    from music_likes as ml
    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 id;

我相信,这道题一定有其他看似简单的解答方法。但是,这道题我还是倾向于运用到经典的剥洋葱思路。

  • 第一步:寻找user_id=1的关注者;
  • 第二步:寻找user_id=1喜欢的music_id
  • 第三步:检索user_id=1的关注者喜欢的music_id,并排除第二步中的检索结果;
  • 第四步:根据id检索music_name,并排序。
MySQL试题答案解析 文章被收录于专栏

MySQL在线编程重点试题解析

全部评论

相关推荐

01-30 22:03
门头沟学院 Java
用微笑面对困难:我滴妈,【俩月】【实习】【主管】仨debuff吃满了,独立设计开发的项目写了绝大占比的运营板块,你独立开发,那维护、问题复盘、日志更新、bug、策划书全是自己整的? 不建议写那么大,可以从小出发更容易
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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