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

月总刷题数和日均刷题数

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

SELECT
	COALESCE(submit_month,'2021汇总') submit_month,
	month_q_cnt,
	avg_day_q_cnt
FROM(
	SELECT 
		DATE_FORMAT(submit_time,'%Y%m') submit_month,
		count(uid) month_q_cnt,
		ROUND(COUNT(uid)/MAX(a.days),3) avg_day_q_cnt
	FROM (
		SELECT *, day(LAST_DAY(submit_time)) days
		FROM practice_record WHERE YEAR(submit_time)='2021'
	) a
	GROUP BY DATE_FORMAT(submit_time,'%Y%m')
	WITH ROLLUP
) b;

全部评论

相关推荐

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