我在 MySQL 中有这个表:
id | Action | DateTime | Time(ms)
-----+------------------------------+----------------------------+-------------
1 | Player1_rightKeyPress_Start | 2014-10-01 18:51:17.795000 | 7322
2 | Player1_shootKeyPress_Start | 2014-10-01 18:51:17.971000 | 7498
3 | Player1_rightKeyPress_Start | 2014-10-01 18:51:18.035000 | 7562
4 | Player2_leftKeyPress_Start | 2014-10-01 18:51:18.126000 | 7653
5 | Player1_shootKeyPress_Start | 2014-10-01 18:51:18.214000 | 7741
6 | Player1_rightKeyPress_Start | 2014-10-01 18:51:18.305000 | 7832
7 | Player2_leftKeyPress_Start | 2014-10-01 18:51:18.369000 | 7896
8 | Player1_shootKeyPress_Start | 2014-10-01 18:51:18.374000 | 7901
9 | Player1_rightKeyPress_Start | 2014-10-01 18:51:18.467000 | 7994
10 | Player1_shootKeyPress_Start | 2014-10-01 18:51:18.580000 | 8107
11 | Player1_rightKeyPress_Start | 2014-10-01 18:51:18.676000 | 8203
12 | Player1_shootKeyPress_Start | 2014-10-01 18:51:18.812000 | 8339
13 | Player1_rightKeyPress_Start | 2014-10-01 18:51:18.899000 | 8426
14 | Player1_shootKeyPress_Start | 2014-10-01 18:51:19.050000 | 8577
15 | Player1_rightKeyPress_Start | 2014-10-01 18:51:19.123000 | 8650
这只是数据库中表的一部分。我想要做的是计算每 10,000 秒内 Player1_rightKeyPress_Start
、Player1_shootKeyPress_Start
和 Player2_leftKeyPress_Start
发生的次数。时间长达 600,000 毫秒。我没有费心将其全部包括在内,因为它真的很大。
最佳答案
您可能可以按照以下方式做一些事情:转换为秒,除以 10 以获得 10 秒的间隔,然后应用分组依据:
SELECT Action, FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(DateTime)/10)), COUNT(*)
FROM myTable
GROUP BY Action, FLOOR(UNIX_TIMESTAMP(DateTime)/10)
检查 mysql 文档中的时间函数。
关于mysql - MySQL 中的算术计算一分钟内的操作数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29584468/