给关系人推荐歌曲

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

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

with t as(
    select 
        f.user_id,
        m_n1.id id1,
        m_n1.music_name name1,
        follower_id,
        m_n2.id id2,
        m_n2.music_name name2
    from follow f
    left join music_likes m1 on f.user_id=m1.user_id
    left join music m_n1 on m1.music_id=m_n1.id
    left join music_likes m2 on follower_id=m2.user_id
    left join music m_n2 on m2.music_id=m_n2.id
),
t2 as(
    select 
        distinct id2,
        name2
    from t
    where user_id=1 
    and (name2 not in (
        select name1 from t
        where user_id=1
    ) or name1 is null)
)
select name2 from t2
order by id2

全部评论

相关推荐

评论
点赞
收藏
分享
牛客网
牛客企业服务