在你的桌子上几乎没有信息,这对你来说只是一个基本的想法,但你可以做这样的事情:-
SELECT COUNT(*)
FROM
(
SELECT a.TimeStamp AS ThisTimeStamp, MIN(b.TimeStamp) AS NextTimeStamp
FROM SomeTable a
INNER JOIN SomeTable b
ON a.TimeStamp < b.TimeStamp
GROUP BY a.TimeStamp
) Sub1
WHERE Sub1.ThisTimeStamp < (Sub1.NextTimeStamp - 600)
获取所有时间戳并将它们与所有其他更大的时间戳结合起来,并使用 MIN 将其缩小到下一个最大的时间戳。然后从中选择差异小于 600 秒的计数(假设 unix 时间戳)。
编辑 - 如果你想为用户限制 10 分钟以上的事件间隔,那么: -
SELECT COUNT(*)
FROM
(
SELECT a.user_id, a.TimeStamp AS ThisTimeStamp, MIN(b.TimeStamp) AS NextTimeStamp
FROM SomeTable a
INNER JOIN SomeTable b
ON a.TimeStamp < b.TimeStamp
AND a.user_id = b.user_id
GROUP BY a.user_id, a.TimeStamp
) Sub1
WHERE Sub1.ThisTimeStamp < (Sub1.NextTimeStamp - 600)