示例:获取在48小时之内重复的记录
SELECT * FROM ( SELECT b.* , LAG(b.OperatorTime, 1, b.OperatorTime) OVER ( PARTITION BY b.No ORDER BY b.OperatorTime ) AS BeforTime , LEAD(b.OperatorTime, 1, b.OperatorTime) OVER ( PARTITION BY b.No ORDER BY b.OperatorTime ) AS NextTime FROM Test b ) a WHERE DATEDIFF(HH, a.BeforTime, a.OperatorTime) < 24 AND DATEDIFF(HH, a.OperatorTime, a.NextTime) < 24 AND a.No IN ( SELECT c.No FROM dbo.Test c GROUP BY c.No HAVING COUNT(c.No) > 1 )