整个解题过程不多说,其他题解说的很明白,但有一个问题是我直接用day(last_day(submit_time))会报错,因为使用group by后select只能选聚合键和聚合函数。但问题是其他人的答案都是直接使用day(last_day(submit_time)),而且我试其他人的答案我全都会报错,有没有哪位高人能解答一下?

select date_format(submit_time, '%Y%m') as submit_month,
       count(*) as month_q_cnt,
       round(count(*) / max(day(last_day(submit_time))), 3) as avg_day_q_cnt
from practice_record
where year(submit_time) = "2021"
group by submit_month
 
union all

select '2021汇总' as submit_month,
        count(*) as month_q_cnt,
        round(count(*) / 31, 3) as avg_day_q_cnt
from practice_record
where year(submit_time) = "2021"
 
order by submit_month