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

月总刷题数和日均刷题数

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

select ifnull(submit_month,'2021汇总') as submit_month,month_q_cnt,avg_day_q_cnt
from (
select date_format(submit_time,'%Y%m') as submit_month,
count(*) as month_q_cnt,
round(count(*)/day(last_day(min(submit_time))),3) as avg_day_q_cnt
from practice_record
where year(submit_time)=2021
group by submit_month with rollup 
order by grouping(submit_month),submit_month ) a

用好group by col1 with rollup 和grouping(col1)

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务