日期:2014-05-17 浏览次数:20425 次
select * from TB a where exists (select * from TB b where b.time > a.time and b.time < dateadd(ss,5,a.time))
------解决方案--------------------
SELECT * FROM TB WHERE EXISTS (SELECT * FROM TB A WHERE ABS(DATEDIFF(SS,A.TIME,B.TIME))<5)
------解决方案--------------------
参照一下这个,对于能用JOIN的联接,尽量少用EXISTS和IN
SELECT * FROM TB A
INNER JOIN TB B
ON A.ID=B.ID
AND A.TIME<>B.TIME
AND ABS(DATEDIFF(SS,A.TIME,B.TIME))<5