MySQL按月、按年、按天、按周統計數據的方法

按日統計

select DATE_FORMAT(date,’%Y%m%d’) days,count(id) count from table group by days;

按周統計

select DATE_FORMAT(date,’%Y%u’) weeks,count(id) count from table group by weeks

按月統計

select DATE_FORMAT(date,’%Y%m’) months,count(id) count from table group by months;

按年統計

select DATE_FORMAT(date,’%Y’) years ,count(id) count from table group by years;;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章