首頁  >  文章  >  資料庫  >  mysql按日、月、周、季度分组_MySQL

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

WBOY
WBOY原創
2016-06-01 13:10:032004瀏覽

按日分组: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;

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn