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

select
    uid,
    count(exam_id) exam_complete_cnt
from
    (
        select
            uid,
            exam_id,
            start_time,
            submit_time,
            dense_rank() over (
                partition by
                    uid
                order by
                    date_format (start_time, '%Y%m') desc
            ) 排名
        from
            test.exam_record
    ) a
where
    排名 <= 3
    and uid not in (
        select distinct
            判断
        from
            (
                select
                    if (submit_time is null, uid, 0) 判断
                from
                    (
                        select
                            uid,
                            exam_id,
                            start_time,
                            submit_time,
                            dense_rank() over (
                                partition by
                                    uid
                                order by
                                    date_format (start_time, '%Y%m') desc
                            ) 排名
                        from
                            test.exam_record
                    ) a
                where
                    排名 <= 3
            ) b
        where
            b.判断 != 0
    )
group by
    uid
order by
    exam_complete_cnt desc,
    uid desc

全部评论

相关推荐

04-11 23:51
门头沟学院 Java
坚定的芭乐反对画饼_许愿Offer版:人人都能过要面试干嘛,发个美团问卷填一下,明天来上班不就好了
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务