题解 | #每份试卷每月作答数和截止当月的作答总数。#

每份试卷每月作答数和截止当月的作答总数。

https://www.nowcoder.com/practice/5f1cbe74c682485aa73e4c2b30f04a62

#方法1
select *
from(
    select exam_id,
    date_format(start_time,"%Y%m") start_month,
    count(uid)  month_cnt
    from exam_record
    group by exam_id,start_month
    )t1
left join 
    (select exam_id,start_month,max(ranking) cum_exam_cnt
     from(
        select exam_id,
        date_format(start_time,"%Y%m") start_month,
        row_number() over(partition by exam_id order by date_format(start_time,"%Y%m")) ranking
        from exam_record
         )t
     group by exam_id,start_month
     ) t2 using(exam_id,start_month)

#方法2
select exam_id,date_format(start_time,"%Y%m") start_month,count(uid) month_cnt,any_value(_exam_cnt)  cum_exam_cnt
from(
    select *,
    (select count(uid) from exam_record d2 where d1.exam_id=d2.exam_id and 
     date_format(d2.start_time,"%Y%m")<= date_format(d1.start_time,"%Y%m")) _exam_cnt 
    from exam_record d1
    ) t
group by exam_id,start_month

全部评论

相关推荐

02-14 15:34
门头沟学院 Java
Java抽象带篮子:专业技能怎么写可以看看我发的帖子
点赞 评论 收藏
分享
2024-12-27 23:45
已编辑
三江学院 Java
程序员牛肉:死局。学历+无实习+项目比较简单一点。基本就代表失业了。 尤其是项目,功能点实在是太假了。而且提问点也很少。第一个项目中的使用jwt和threadlocal也可以作为亮点写出来嘛?第二个项目中的“后端使用restful风格”,“前端采用vue.JS”,“使用redis”也可以作为亮点嘛? 项目实在是太简单了,基本就是1+1=2的水平。而你目标投递的肯定也是小厂,可小厂哪里有什么培养制度,由于成本的问题,人家更希望你来能直接干活,所以你投小厂也很难投。基本就是死局,也不一定非要走后端这条路。可以再学一学后端之后走测试或者前端。 除此之外,不要相信任何付费改简历的。你这份简历没有改的必要了,先沉淀沉淀
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
正在热议
更多
牛客网
牛客企业服务