码迷,mamicode.com
首页 > 数据库 > 详细

mysql按天,按周,按月,按季度,按年统计数据

时间:2017-12-08 18:21:01      阅读:278      评论:0      收藏:0      [点我收藏+]

标签:where   rom   date()   int   color   date   weight   mys   bsp   


SELECT
count(id)
FROM
rd_track_info
WHERE
DATE(create_time) < DATE_SUB(CURDATE(), INTERVAL 7 DAY);

SELECT
count(id)
FROM
rd_track_info
WHERE
DATE(create_time) = DATE_SUB(CURDATE(), INTERVAL 7 DAY);

SELECT
count(id)
FROM
rd_track_info
WHERE
DATE(create_time) > DATE_SUB(CURDATE(), INTERVAL 7 DAY);

 

/*按天统计*/
SELECT
    count(id) countNum,
    DATE(create_time) createTime
FROM
    rd_track_info
GROUP BY
    DATE(create_time)
ORDER BY
    DATE(create_time) DESC;


/*按周统计*/
SELECT
    count(id) countNum,
    WEEK(create_time) createTime
FROM
    rd_track_info
GROUP BY
    WEEK(create_time)
ORDER BY
    WEEK(create_time) DESC;


/*按月统计*/
SELECT
    count(id) countNum,
    MONTH(create_time) createTime
FROM
    rd_track_info
GROUP BY
    MONTH(create_time)
ORDER BY
    MONTH(create_time) DESC;


/*按季度统计*/
SELECT
    count(id) countNum,
    QUARTER(create_time) createTime
FROM
    rd_track_info
GROUP BY
    QUARTER(create_time)
ORDER BY
    QUARTER(create_time) DESC;

/*按年统计*/
SELECT
    count(id) countNum,
    YEAR(create_time) createTime
FROM
    rd_track_info
GROUP BY
    YEAR(create_time)
ORDER BY
    YEAR(create_time) DESC;

 

mysql按天,按周,按月,按季度,按年统计数据

标签:where   rom   date()   int   color   date   weight   mys   bsp   

原文地址:http://www.cnblogs.com/lazyInsects/p/8006388.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!