9
mysql 如何按时间维度每 5s 统计一次数据呢?
source link: https://www.v2ex.com/t/803372
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
mysql 如何按时间维度每 5s 统计一次数据呢?
有个表有创建时间字段,按照这个字段,每隔 5 秒统计一次这期间的数据增量,如果没有新增,则为 0,这种 SQL 怎么写呢?
11 条回复 • 2021-09-22 16:15:37 +08:00
Geekerstar 2 小时 4 分钟前
@myd
2021-09-22 13:45:29 1
2021-09-22 13:45:30 2
2021-09-22 13:46:00 4
2021-09-22 13:46:07 1
2021-09-22 13:46:30 2
不是每秒钟都有数据,有没有办法能整齐的每五秒分割一次来进行统计呢?
2021-09-22 13:45:29 1
2021-09-22 13:45:30 2
2021-09-22 13:46:00 4
2021-09-22 13:46:07 1
2021-09-22 13:46:30 2
不是每秒钟都有数据,有没有办法能整齐的每五秒分割一次来进行统计呢?
Pipecraft 35 分钟前
试了一下,使用 `DATE_ADD(created_at, INTERVAL - SECOND(created_at) % 5 SECOND)` 可以按照每分钟的 0,5,10.. 秒为单位统计。没有数据的时间段需要在程序补齐。
由于无法贴出代码,我把完整的 SQL 贴在了这里 pzwd.net/d/31/2 。
由于无法贴出代码,我把完整的 SQL 贴在了这里 pzwd.net/d/31/2 。
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK