0

假设我有跟随表


| 身份证 | 团队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 | 2 | 2013-07-27 10:29:00 |

| 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 | 3 | 2013-07-27 10:30:00 |

| 13 | 3 | 2013-07-27 10:31:00 |

有人可以告诉我正确的解决方法吗

tnx

4

1 回答 1

1

以下 sql 语句将返回您想要的列表:

SELECT table1.id, table1.teamid, table1.timestamp FROM exampleTable table1, exampleTable table2 where table1.id != table2.id AND table1.teamid = table2.teamid AND ABS(table1.timestamp - table2.timestamp) < 400 ORDER BY团队,身份证

于 2013-08-10T13:53:31.703 回答