题解 | #每个月Top3的周杰伦歌曲#

每个月Top3的周杰伦歌曲

https://www.nowcoder.com/practice/4ab6d198ea8447fe9b6a1cad1f671503

select
    tt.month,
    tt.ranking,
    tt.song_name,
    tt.play_pv
from
(select
    t.month,
    t.song_name,
    t.song_id,
    t.play_pv,
    rank() over(partition by t.month order by t.play_pv desc,t.song_id asc) as ranking
from
    (select 
        month(a.fdate) as month,
        b.song_name,
        b.song_id,
        count(*) as play_pv
    from
        play_log a
    left join 
        song_info b on a.song_id = b.song_id
    left join 
        user_info c on a.user_id = c.user_id
    where 
        year(a.fdate) = 2022 and c.age between 18 and 25 and b.singer_name = '周杰伦'
    group by 
        1,2,3) t
) tt
where tt.ranking <= 3
order by tt.month,tt.ranking

全部评论

相关推荐

11-04 19:05
已编辑
东莞城市学院 单片机
不知道怎么取名字_:你这个要实习两年?哪有这么久的,感觉就是即使你毕业了,但还按实习的话,是不是不用给你缴社保公积金啥的
点赞 评论 收藏
分享
有气魄的马来熊在摸鱼:我爱vivo 马上换手机 vivo我爱你!!!
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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