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

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

https://www.nowcoder.com/practice/13415dff75784a57bedb6d195262be7b

# 1. 2021年、2020年上半年各类试卷的做完次数, 以及排名
with newtable as (
    select 
        tag, 
        year(start_time) start_year,
        count(score) exam_cnt,
        rank() over (partition by year(start_time) order by count(score) DESC) exam_cnt_rank
    from exam_record 
    join examination_info using(exam_id)
    where year(start_time) in (2020,2021) and month(start_time)<=6
    group by tag, year(start_time)
    having exam_cnt > 0     #过滤作答数为0的记录
)
# 2. 合并,求增长率、排名变化
select 
    a.tag tag, 
    a.exam_cnt exam_cnt_20,
    b.exam_cnt exam_cnt_21,
    concat(round((b.exam_cnt - a.exam_cnt)/a.exam_cnt*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  #直接相减出现报错BIGINT UNSIGNED,需要转化格式为整数signed
from newtable a join newtable b 
on a.tag=b.tag and a.start_year=2020 and b.start_year=2021 
order by growth_rate DESC, exam_cnt_rank_21 DESC

全部评论

相关推荐

点赞 评论 收藏
分享
暴杀流调参工作者:春招又试了一些岗位,现在投递很有意思,不仅要精心准备简历,投递官网还得把自己写的东西一条一条复制上去,阿里更是各个bu都有自己的官网,重复操作无数次,投完简历卡完学历了,又该写性格测评、能力测评,写完了又要写专业笔试,最近还有些公司搞了AI辅助编程笔试,有些还有AI面试,对着机器人话也听不明白录屏硬说,终于到了人工面试又要一二三四面,小组成员面主管面部门主管面hr面,次次都没出错机会,稍有不慎就是挂。 卡学历卡项目卡论文卡实习什么都卡,没有不卡的😂
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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