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

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

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

# 2021年上半年各类试卷的做完次数  以及 同比
# 以及做完次数排名变化,按照增长率📈  和  21年排名降序输出
# 字段要求:tag\20年做完次数\21年做完次数\同比\20排名\21排名\排名增长数

# 表一:链接
with table1 as (
    select tag,uid,exam_id,submit_time
    from exam_record left join examination_info using(exam_id)
    where submit_time is not null 
    And year(submit_time) between 2020 and 2021
    AND month(submit_time) between 1 and 6
),
# 表二:按照tag、year进行分类计算
# 注意点:groupby按照tag、year分组,partition 按照year分组
# 注意点:排名允许并列且跳过,用rank
table2 as(
    select tag,year(submit_time) as start_year,COUNT(submit_time) as exam_cnt,rank()over(partition by year(submit_time) order by count(submit_time) desc) as exam_cnt_rank
    from table1
    group by tag,year(submit_time)
),
# 表三: 感觉要用lead函数?
table3 as(
    select tag,
    (case when start_year=2020 then exam_cnt else 0 end) as exam_cnt_20,
    lead(exam_cnt,1)over(partition by tag order by start_year) as exam_cnt_21,
    concat(round((lead(exam_cnt,1)over(partition by tag order by start_year)-(case when start_year=2020 then exam_cnt else 0 end))/(case when start_year=2020 then exam_cnt else 0 end)*100,1),"%") as growth_rate,	


    (case when start_year=2020 then exam_cnt_rank else 0 end) as exam_cnt_rank_20,
    lead(exam_cnt_rank,1)over(partition by tag order by start_year) as exam_cnt_rank_21,
    (lead(exam_cnt_rank,1)over(partition by tag order by start_year)-(case when start_year=2020 then exam_cnt_rank else 0 end)) as rank_delta
    from table2
)

select *
from table3
where growth_rate is not null
order by exam_cnt_20 asc

全部评论

相关推荐

投递华为等公司10个岗位
点赞 评论 收藏
转发
点赞 收藏 评论
分享
正在热议
# 牛客帮帮团来啦!有问必答 #
1152069次浏览 17149人参与
# 通信和硬件还有转码的必要吗 #
11209次浏览 101人参与
# OPPO开奖 #
19224次浏览 267人参与
# 和牛牛一起刷题打卡 #
19023次浏览 1635人参与
# 实习与准备秋招该如何平衡 #
203428次浏览 3627人参与
# 大厂无回复,继续等待还是奔赴小厂 #
4975次浏览 30人参与
# 不去互联网可以去金融科技 #
20468次浏览 256人参与
# 通信硬件薪资爆料 #
265962次浏览 2484人参与
# 国企是理工四大天坑的最好选择吗 #
2227次浏览 34人参与
# 互联网公司评价 #
97718次浏览 1280人参与
# 简历无回复,你会继续海投还是优化再投? #
25039次浏览 354人参与
# 0offer是寒冬太冷还是我太菜 #
454907次浏览 5124人参与
# 国企和大厂硬件兄弟怎么选? #
53918次浏览 1012人参与
# 参加过提前批的机械人,你们还参加秋招么 #
14646次浏览 349人参与
# 硬件人的简历怎么写 #
82289次浏览 852人参与
# 面试被问第一学历差时该怎么回答 #
19401次浏览 213人参与
# 你见过最离谱的招聘要求是什么? #
28194次浏览 248人参与
# 学历对求职的影响 #
161253次浏览 1804人参与
# 你收到了团子的OC了吗 #
538774次浏览 6387人参与
# 你已经投递多少份简历了 #
344269次浏览 4963人参与
# 实习生应该准时下班吗 #
96988次浏览 722人参与
# 听劝,我这个简历该怎么改? #
63525次浏览 622人参与
牛客网
牛客企业服务