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

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

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

#  各类试卷的做完次数  上半年  同期的增长率
# rank

with table1 as(
    select tag, date_format(start_time,"%Y") as start_year,
    date_format(submit_time,"%Y%m") as submit_time
    from exam_record left join examination_info using(exam_id)
    where month(submit_time) <= 6 
),
table2 as (
    select tag,start_year,
    count(submit_time) as exam_cnt
    # rank()over(partition by start_year order by submit_month) as exam_cnt_rank 
    from table1 
    group by tag, start_year
),
table3 as(
    select * , rank()over(partition by start_year order by exam_cnt desc) as exam_cnt_rank
    from table2 
),
table4 as(
    select tag , 
    max(if(start_year = '2020',exam_cnt,0)) as exam_cnt_20,
    max(if(start_year = '2021',exam_cnt,0)) as exam_cnt_21,
    max(if(start_year = '2020',exam_cnt_rank,0)) as exam_cnt_rank_20,
    max(if(start_year = '2021',exam_cnt_rank,0)) as exam_cnt_rank_21
    from table3
    group by tag
)
select tag,exam_cnt_20,exam_cnt_21,
concat(round(((exam_cnt_21 - exam_cnt_20)/exam_cnt_20) * 100,1),'%') as growth_rate,
exam_cnt_rank_20,exam_cnt_rank_21,
(exam_cnt_rank_21 - exam_cnt_rank_20) as rank_delta
from table4
where exam_cnt_rank_21 != 0 and exam_cnt_rank_20 != 0
order by growth_rate desc,exam_cnt_rank_21 desc

全部评论

相关推荐

offer多多的六边形战士很无语:看了你的博客,感觉挺不错的,可以把你的访问量和粉丝数在简历里提一下,闪光点(仅个人意见)
点赞 评论 收藏
分享
10-25 12:05
已编辑
湖南科技大学 Java
若梦难了:我有你这简历,已经大厂乱杀了
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务