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

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

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

# table exam_record 
# 每份试卷 每月作答数 
# 每份试卷 截止当月作答数 (累加) sum order by
# 根据示例可知只要有starttime 就算作答
with temp as (
    select exam_id,
        date_format(start_time, '%Y%m') time1
    from exam_record
)
select e.*,
    sum(e.month_cnt) over (partition by e.exam_id order by e.start_month) cum_exam_cnt
from(
    select exam_id, time1 start_month,
        count(*) month_cnt
    from temp
    group by exam_id, time1
) e
order by exam_id, start_month;

全部评论

相关推荐

07-30 11:52
门头沟学院 Java
美团暑期实习没投递成功,这次正式批的北斗计划总该有我的一部分了吧!
求职的纳鲁多:大佬投我就不投了,毕竟王不见王,避你锋芒
点赞 评论 收藏
分享
06-28 22:48
已编辑
广东金融学院 Java
小浪_Coding:学院本+这俩项目不是buff叠满了嘛
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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