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

月总刷题数和日均刷题数

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

#大力飞砖写法 避免ONLY_FULL_GROUP_BY COALESCE 
select distinct  t1.submit_month,t1.month_q_cnt,round(t1.month_q_cnt/t2.monthday,3)avg_day_q_cnt
from(
select date_format(submit_time,'%Y%m') as submit_month,count(*) as month_q_cnt
from practice_record
where year(submit_time)='2021'
group by submit_month
)as t1 -- 计算月均
inner join 
(
select date_format(submit_time,'%Y%m') as submit_month,
datediff(DATE_ADD(submit_time,INTERVAL 1 MONTH),submit_time) as monthday
from practice_record -- 计算日均
)as t2 on t1.submit_month=t2.submit_month 
union
(
select '2021汇总',count(*),round(count(*)/31,3)
from practice_record
where year(submit_time)='2021'
)
order by submit_month

全部评论

相关推荐

牛客41406533...:回答他在课上学,一辈子待在学校的老教授用三十年前的祖传PPT一字一句的讲解,使用谭浩强红皮书作为教材在devc++里面敲出a+++++a的瞬间爆出114514个编译错误来学这样才显得专业
点赞 评论 收藏
分享
评论
4
2
分享

创作者周榜

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