本文主要是介绍mysql按照天、月份、年份统计查询,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
按月份查询
SELECT * FROM tbl_order GROUP BY DATE_FORMAT(CreateTime,'%Y-%m');
SELECT sum(money), DATE_FORMAT(CreateTime,'%Y-%m') FROM tbl_order GROUP BY DATE_FORMAT(CreateTime,'%Y-%m');
按天查询
SELECT * FROM tbl_bill GROUP BY DATE_FORMAT(CreateTime,'%Y-%m-%d');
SELECT sum(Income), DATE_FORMAT(CreateTime,'%Y-%m-%d') FROM tbl_bill GROUP BY DATE_FORMAT(CreateTime,'%Y-%m-%d');
这篇关于mysql按照天、月份、年份统计查询的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!