题解 | 试卷完成数同比2020年的增长率及排名变化

select
    a.tag,
    a.exam_cnt exam_cnt_20,
    b.exam_cnt exam_cnt_21,
    concat (
        round(((b.exam_cnt / a.exam_cnt) -1) * 100, 1),
        '%'
    ) growth_rate,
    a.exam_cnt_rank exam_cnt_rank_20,
    b.exam_cnt_rank exam_cnt_rank_21,
    cast(b.exam_cnt_rank as signed) - cast(a.exam_cnt_rank as signed) rank_delta
from
    (
        select
            tag,
            year (start_time) start_year,
            sum(
                case
                    when submit_time is not null then 1
                    else 0
                end
            ) exam_cnt,
            rank() over (
                order by
                    sum(
                        case
                            when submit_time is not null then 1
                            else 0
                        end
                    ) desc
            ) exam_cnt_rank
        from
            test.examination_info ei
            join test.exam_record er on ei.exam_id = er.exam_id
        where
            year (start_time) = 2020
            and month (start_time) <= 6
        group by
            tag,
            year (start_time)
        having
            exam_cnt != 0
    ) a
    join (
        select
            tag,
            year (start_time) start_year,
            sum(
                case
                    when submit_time is not null then 1
                    else 0
                end
            ) exam_cnt,
            rank() over (
                order by
                    sum(
                        case
                            when submit_time is not null then 1
                            else 0
                        end
                    ) desc
            ) exam_cnt_rank
        from
            test.examination_info ei
            join test.exam_record er on ei.exam_id = er.exam_id
        where
            year (start_time) = 2021
            and month (start_time) <= 6
        group by
            tag,
            year (start_time)
        having
            exam_cnt != 0
    ) b on a.tag = b.tag
order by
    growth_rate desc,
    exam_cnt_rank_21 desc

全部评论

相关推荐

03-25 19:00
东北大学 Java
程序员牛肉:太好了,是聊天记录。不得不信了。 当个乐子看就好,不要散播焦虑
点赞 评论 收藏
分享
03-28 00:50
已编辑
武汉理工大学 Java
礼堂顶真:一般都是横向对比挂的,很少hr面本身挂人,除非答的太逆天
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务