题解 | #月总刷题数和日均刷题数#
月总刷题数和日均刷题数
https://www.nowcoder.com/practice/f6b4770f453d4163acc419e3d19e6746
select coalesce(submit_month,'2021汇总') ,month_q_cnt,avg_day_q_cnt
from
(
SELECT
DATE_FORMAT(submit_time,"%Y%m") submit_month,
COUNT(submit_time) month_q_cnt,
round(COUNT(submit_time) / MAX(DAY(last_day(submit_time))),3) avg_day_q_cnt
FROM
practice_record
WHERE
year(submit_time) = '2021'
GROUP BY
submit_month
WITH ROLLUP
) t