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

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

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

with a as 
(select tag, year(start_time) as start_year, count(submit_time) as exam_cnt, rank() over(partition by year(start_time) order by count(submit_time) desc) as exam_cnt_rank
from examination_info as ei 
left join exam_record as er
on ei.exam_id=er.exam_id
where  month(start_time)<=6 and (year(start_time)=2021 or year(start_time)=2020)
group by year(start_time),tag
having count(submit_time) !=0)

select tag, 
    sum(if(start_year=2020, exam_cnt,0)) as exam_cnt_20, 
    sum(if(start_year=2021, exam_cnt,0)) as exam_cnt_21, 
    concat(format((sum(if(start_year=2021, exam_cnt,0))-sum(if(start_year=2020, exam_cnt,0)))/sum(if(start_year=2020, exam_cnt,0))*100,1),'%' )as growth_rate, 
    sum(if(start_year=2020, exam_cnt_rank,0)) as exam_cnt_rank_20,
    sum(if(start_year=2021, exam_cnt_rank,0)) as exam_cnt_rank_21,
    sum(if(start_year=2021, exam_cnt_rank,0))-sum(if(start_year=2020, exam_cnt_rank,0)) as rank_delta
from a
group by tag
having count(start_year)=2
order by growth_rate desc,exam_cnt_rank_21 desc

全部评论

相关推荐

11-08 17:36
诺瓦科技_HR
点赞 评论 收藏
分享
评论
1
收藏
分享
牛客网
牛客企业服务