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

月总刷题数和日均刷题数

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

使用union把2021汇总与原表查询汇总到一起,一开始运行老是报错,找了好久才发现分组后没有处理day (last_day (submit_time)),加了个max就显示本月的最大天数了,后面发现没有这个where实例通过不了.
(select
    date_format (submit_time, '%Y%m') submit_month,
    count(1) month_q_cnt,
    ROUND(count(1) / max(day (last_day (submit_time))), 3) avg_day_q_cnt
from
    practice_record
where 
    year(submit_time)=2021
group by
    submit_month)
union
(select
    '2021汇总' as submit_month,
    count(*) submit_month,
    ROUND(count(*) / max(day (last_day (submit_time))), 3) avg_day_q_cnt
from
    practice_record
where 
    year(submit_time)=2021) 
order by 
    submit_month;

全部评论

相关推荐

昨天 13:52
武汉大学 golang
点赞 评论 收藏
分享
点赞 评论 收藏
分享
就在我现在公司的隔壁每天经过都唏嘘不已(就是羡慕)什么时候可以到这里上班啊
柯基在debug:从大学毕业投简历到现在了,应届的时候我都面到终面了,现在工作四年了连简历初筛都过不了了
投递莉莉丝游戏等公司9个岗位
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

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