Rumah > Artikel > pangkalan data > mysql按日、月、周、季度分组_MySQL
按日分组: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;