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

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

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

知识点

  • 窗口函数dense_rank :生成1223类的连续数字排序

可以看一下这个子查询的执行结果,这是根据start_time进行排序。

为什么要用start_time呢?如果用submit_time来排序的话,因为我们要正确理解近三个月试卷全部完成的这个信息,用submit_time来排序的话,就会将未完成的那个试卷所在的月份也算进来了。

这里还不是很懂。

外层查询条件

where

recent_months <= 3

是因为我们只需要统计近三个月的

select
    uid,
    count(submit_time) as exam_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 recent_months
        from
            exam_record
    ) recent_table
where
    recent_months <= 3
group by
    uid
having
    count(submit_time) = count(start_time)
order by
    exam_complete_cnt desc,
    uid desc

全部评论

相关推荐

求求给个offer我...:有这60不如v我50
点赞 评论 收藏
分享
10-17 09:06
门头沟学院 Java
LZStarV:(这居然能又刷到你)感觉真的就是岗位少了吧,项目很多27届这个点都差不多这个水准,只能说有点不赶趟了先慢慢投吧兄弟,啥都投一下总有机会的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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