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

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

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

分步骤进行:1、先把未完成率前百分之50的人找出来,用到ntile()over()开窗函数
                      2、再把每个用户近三月的完成情况查出来
                      3、根据前两步的结果进行关联,选择符合条件的用户即可
select t1.uid,start_month,total_cnt,complete_cnt
from user_info t1
join (
       select uid,date_format(start_time,'%Y%m') as start_month,
              count(1) as total_cnt,count(submit_time) as complete_cnt
       from (
           select uid,start_time,submit_time,
                  dense_rank()over(partition by uid order by date_format(start_time,'%Y%m') desc) as rn
           from exam_record
            ) t
       where rn <= 3
       group by uid,date_format(start_time,'%Y%m')
      ) t2 
on t1.uid = t2.uid
where level in (6,7) 
and t1.uid in (
            select uid 
            from (
                  select uid,incomplete_rate,
                         ntile(2)over(order by incomplete_rate desc) as rn
                  from(
                      select uid,sum(if(submit_time is null,1,0))/count(1) as incomplete_rate
                      from examination_info t1
                      join exam_record t2 on t1.exam_id = t2.exam_id
                      where tag = 'SQL'
                      group by uid
                      )t
                 ) tt
            where rn = 1
        )
order by uid,start_month



全部评论

相关推荐

02-25 16:55
已编辑
北京工业大学 Java
211本,找日常实习的话,如果面向中厂的话,需要刷hot100么?因为之前从来没刷过,算法仅限于学校课程水平,准备3月投递简历,现在还需要背八股文,时间有些紧张,还需要刷算法题么?同时什么样的公司可以算是中厂呢?
程序员小白条:中大厂说的上名字的,必定要算法,hot100只是最基础的了,题库远不止100题捏,一般在300-400题量之间,算法=学校课程=简单题也做不出,多准备八股文和算法吧,其他项目可以放放,精刷算法就行了,花时间成长很快的
点赞 评论 收藏
分享
01-14 16:23
广州商学院 Java
双非后端失败第N人:如果准备好了可以直接投字节,字节是最不看学历的,只要想面,大概率都能给你约面。
双非有机会进大厂吗
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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