题解 | #未完成率较高的50%用户近三个月答卷情况#

未完成率较高的50%用户近三个月答卷情况

https://www.nowcoder.com/practice/3e598a2dcd854db8b1a3c48e5904fe1c

select t3.*
from
(
 select
uid
,start_month
,sum(total_cnt) total_cnt
,sum(complete_cnt) complete_cnt
from
(
  select
uid
,date_format(start_time,'%Y%m') start_month
,count(start_time) total_cnt
,count(submit_time) complete_cnt
,row_number()over(partition by uid order by date_format(start_time,'%Y%m'desc) rn
from exam_record
left join user_info using(uid)
where level in('6','7')
group by uid,date_format(start_time,'%Y%m')
) t2
where t2.rn<=3 
group by uid
,start_month   
) t3
join
(
select
uid
from
(
select
uid,ntile(2)over(order by rn) nt
from 
(
select
uid
,count(submit_time) finish
,count(a.exam_id) al
,row_number()over(order by count(case when submit_time is null then 1 else null end) /count(a.exam_id) desc) rn
from exam_record a
left join examination_info b on a.exam_id=b.exam_id
where tag='SQL'
group by uid
) t
) t1
where nt=1

) t4 using(uid)
order by uid,start_month
按照 t,t1,t2,t3,t4分别写逻辑,注意ntile()over()用法



#MySQL#
全部评论

相关推荐

06-13 10:15
门头沟学院 Java
想去夏威夷的大西瓜在...:我也是27届,但是我现在研一下了啥项目都没有呀咋办,哎,简历不知道咋写
点赞 评论 收藏
分享
07-07 14:30
复旦大学 Java
遇到这种人我也不知道说啥了
无能的丈夫:但我觉得这个hr语气没什么问题啊(没有恶意
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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