mysql - MySQL 中的算术计算一分钟内的操作数

标签 mysql datetime

我在 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_StartPlayer1_shootKeyPress_StartPlayer2_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/

相关文章:

java - MYSQL 连接器说即使用户名错误也已连接?

mysql - 无法连接到数据库

mySQL查询代码和索引优化

python - Django:按日期范围过滤对象

c# - 如何在 C# 中将 DateTime 格式化为 "Oct. 10, 2008 10:43am CST"

c# - C#中的日期比较

c# - double 到 datetime 的转换总是失败

r - R 中是否有检查时间间隔是否在单列中重叠并按组排序的函数

PHP 将表单数据发送到数据库时出错

php - 如何限制功能并包含php脚本可以运行?