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

每个月Top3的周杰伦歌曲

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

with
    tb_month as (
        select
            # SUBSTR(TO_CHAR(fdate,'yyyymmdd'),1,4 ) as year,
            #        SUBSTR(TO_CHAR(fdate,'yyyymmdd'),5,2 ) as month,
            month(fdate) as month,
            year(fdate) as year,
            fdate,
            user_id,
            song_id
        from
            play_log
    )
select
    *
from
    (
        select
            tm.month,
            Row_NUMBER() over (
                partition by
                    tm.month
                order by
                    count(tm.song_id) desc,
                    tm.song_id asc
            ) as ranking,
            si.song_name,
            count(tm.song_id) play_pv
        from
            song_info si
            inner join tb_month tm on tm.song_id = si.song_id
            left join user_info ui on ui.user_id = tm.user_id
        where
            si.singer_name = '周杰伦'
            and ui.age between 18 and 25
            and tm.year = 2022
        group by
            tm.month,
            si.song_name,
            si.song_id
    ) rt
where
    ranking <= 3;

全部评论
不足的是没有oracle的环境选择
点赞 回复 分享
发布于 05-02 18:33 广东

相关推荐

求职老司机:前端比后端还难 hc 砍一半 不如学点 node 偏全栈
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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