我想返回表中彼此相距5分钟的所有行。
示例表:
dgesvd
是我们在5分钟内查询
我曾尝试svd( X, 'econ')
和X
时间这样做,但我似乎无法完全实现这一目标。
答案 0 :(得分:0)
您应该与自己和write()
put:
ON clause
答案 1 :(得分:0)
DATEADD是一个选项,但它有点复杂。更好的选择是使用DATEDIFF:
--Test Setup:
DECLARE @sourceTable AS TABLE (KillID int PRIMARY KEY IDENTITY(1,1), KillTime datetime2(7) NOT NULL);
INSERT INTO @sourceTable (KillTime)
VALUES
('2016/02/02 10:01'),
('2016/02/02 10:05'),
('2016/02/02 10:09'),
('2016/02/02 10:30')
--Code:
SELECT *
FROM @sourceTable AS ST1
INNER JOIN @sourceTable AS ST2
ON ST2.KillID < ST1.KillID --Only the smaller IDs so we do not get self joins or duplicates (1 to 2 and 2 to 1).
AND DATEDIFF(second, ST2.KillTime, ST1.KillTime) BETWEEN -300 AND 300; --300 seconds is 5 minutes
使用秒而不是分钟来减少舍入/截断问题。