MySQL 统计单表增量数据
按天查看表的增量数据:
SELECT
DATE(create_time) as date,
COUNT(*) as daily_increment
FROM
table_name
WHERE
create_time >= '2024-01-01'
AND create_time < '2024-12-16' + INTERVAL 1 DAY
GROUP BY
date;
按小时查看表的增量数据:
SELECT
DATE_FORMAT(create_time, '%Y-%m-%d %H:00:00') as hour,
COUNT(*) as incremental_count
FROM
table_name
WHERE
create_time >= '2024-12-01 00:00:00' AND
create_time <= '2024-12-16 23:59:59'
GROUP BY
hour
ORDER BY
hour;