欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

按年、月、周、日统计数据

程序员文章站 2022-04-06 16:43:23
...
/*按天统计*/
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;
相关标签: 应用场景