题解 | #月总刷题数和日均刷题数#

月总刷题数和日均刷题数

https://www.nowcoder.com/practice/f6b4770f453d4163acc419e3d19e6746

select
    submit_month,
    cnt month_q_cnt,
    format (
        cnt / DAY (
            LAST_DAY (cast(concat (submit_month, '01') as date))
        ),
        3
    ) avg_day_q_cnt
from
    (
        select
            date_format (submit_time, '%Y%m') submit_month,
            count(id) cnt
        from
            practice_record
        where
            date_format (submit_time, '%Y') = '2021'
        group by
            date_format (submit_time, '%Y%m')
    ) a
    
union all
select
    '2021汇总' submit_month,
    cnt month_q_cnt,
    format (cnt / 31, 3) avg_day_q_cnt
from
    (
        select
            date_format (submit_time, '%Y') submit_month,
            count(id) cnt
        from
            practice_record
        where
            date_format (submit_time, '%Y') = '2021'
        group by
            date_format (submit_time, '%Y')
    ) a
order by submit_month

全部评论

相关推荐

Noob1024:一笔传三代,人走笔还在
点赞 评论 收藏
分享
qz鹿:*** 祝他毕业就失业
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务