假设我有以下表格
<小时/>|身份证 |团队ID |时间戳|
| 5 | 1 | 2013-07-27 10:19:00 |
| 6 | 2 | 2013-07-27 10:20:00 |
| 7 | 1 | 2013-07-27 10:25:00 |
| 8 | 3 | 2013-07-27 10:26:00 |
| 9 | 1 | 2013-07-27 10:28:00 |
| 10 | 10 2 | 2013-07-27 10:29:00 |
| 11 | 11 3 | 2013-07-27 10:30:00 |
| 13 | 3 | 2013-07-27 10:31:00 |
我需要的是时间戳之间的间隔小于 4 分钟并按团队 ID 分组的记录
所以输出需要看起来像
| 7 | 1 | 2013-07-27 10:25:00 |
| 9 | 1 | 2013-07-27 10:28:00 |
| 11 | 11 3 | 2013-07-27 10:30:00 |
| 13 | 3 | 2013-07-27 10:31:00 |
谁能告诉我正确的解决方法
tnx
最佳答案
以下sql语句将返回您想要的列表:
SELECT table1.id、table1.teamid、table1.timestamp FROM exampleTable table1, exampleTable table2 其中 table1.id != table2.id AND table1.teamid = table2.teamid AND ABS(表 1.时间戳 - 表 2.时间戳) < 400 ORDER BY teamid, id
关于Mysql 显示时间戳间隔低于 4 分钟的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18162234/