mysql按日、月、周、季度分组

时间:2021-08-10 09:43:21
按日分组:select DATE_FORMAT(o.OrderDate,'%Y%m%d') weeks,count(*) count from orders o group by weeks;
按月分组:select DATE_FORMAT(o.OrderDate,'%Y%m') weeks,count(*) count from orders o group by weeks;

按周分组: select DATE_FORMAT(o.OrderDate,'%Y_%u') weeks,count(*) count from orders o group by weeks;

按季度分组:select CONCAT(YEAR(o.OrderDate),'_',quarter(o.OrderDate)) qu,count(*) count from orders o group by qu;

获取当月的最后一天 select LAST_DAY(o.OrderDate) FROM orders o