题解 | #近三个月未完成试卷数为0的用户完成情况#

近三个月未完成试卷数为0的用户完成情况

https://www.nowcoder.com/practice/4a3acb02b34a4ecf9045cefbc05453fa

这题就是一个很基础得题了,逻辑简单,应该都会。题目中的描述还是比较清楚,就不过多打一堆废话。

这里用得变量去做,开窗自己去开

select
d.uid,sum(d.startNum) as exam_complete_cnt
from 
(
    select
    b.uid,b.startNum,b.submitNum, (case when @preCol = b.uid then @rk:=@rk+1 else @rk:=1 end) as rk,@preCol:=b.uid
    from 
    (
        select
        a.uid, date_format(start_time,"%Y%m") as date,count(1) as startNum, 
        sum(case when a.submit_time is null then 0 else 1 end) as submitNum
        from exam_record a
        group by a.uid, date_format(start_time,"%Y%m") 
    ) b ,(Select @preCol:=NULL,@rk:=0) c

    order by b.uid desc,b.date desc
) d where d.rk <= 3

group by d.uid having sum(d.startNum) = sum(d.submitNum)

order by exam_complete_cnt desc,d.uid desc

全部评论

相关推荐

头像 会员标识
昨天 17:08
已编辑
牛客_产品运营部_私域运营
腾讯 普通offer 24k~26k * 15,年包在36w~39w左右。
点赞 评论 收藏
分享
我见java多妩媚:大外包
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务