select * from tbl where datediff(mi,'9:11:00',dt)<2
declare @t table (t datetime )insert into @t select '9:05' union all select '9:11' union all select '9:15' union all select '9:16' union all select '9:25' union all select '9:26'select * from @t select t from @t a where exists (select 1 from @t where a.t <t and datediff(mi,a.t,t)<=2) t ------------------------------------------------------ 1900-01-01 09:05:00.000 1900-01-01 09:11:00.000 1900-01-01 09:15:00.000 1900-01-01 09:16:00.000 1900-01-01 09:25:00.000 1900-01-01 09:26:00.000(所影响的行数为 6 行)t ------------------------------------------------------ 1900-01-01 09:15:00.000 1900-01-01 09:25:00.000(所影响的行数为 2 行)
oh 搞错了! sorry declare @t table (t datetime )insert into @t select '9:05' union all select '9:11' union all select '9:15' union all select '9:16' union all select '9:25' union all select '9:26'select * from @t select t from @t a where exists (select 1 from @t where a.t >t and datediff(mi,t,a.t)<=2)t ------------------------------------------------------ 1900-01-01 09:05:00.000 1900-01-01 09:11:00.000 1900-01-01 09:15:00.000 1900-01-01 09:16:00.000 1900-01-01 09:25:00.000 1900-01-01 09:26:00.000(所影响的行数为 6 行)t ------------------------------------------------------ 1900-01-01 09:16:00.000 1900-01-01 09:26:00.000(所影响的行数为 2 行)
select '9:05' union all
select '9:11' union all
select '9:15' union all
select '9:16' union all
select '9:25' union all
select '9:26'select * from @t select t
from @t a
where exists (select 1 from @t where a.t <t and datediff(mi,a.t,t)<=2)
t
------------------------------------------------------
1900-01-01 09:05:00.000
1900-01-01 09:11:00.000
1900-01-01 09:15:00.000
1900-01-01 09:16:00.000
1900-01-01 09:25:00.000
1900-01-01 09:26:00.000(所影响的行数为 6 行)t
------------------------------------------------------
1900-01-01 09:15:00.000
1900-01-01 09:25:00.000(所影响的行数为 2 行)
sorry
declare @t table (t datetime )insert into @t
select '9:05' union all
select '9:11' union all
select '9:15' union all
select '9:16' union all
select '9:25' union all
select '9:26'select * from @t select t
from @t a
where exists (select 1 from @t where a.t >t and datediff(mi,t,a.t)<=2)t
------------------------------------------------------
1900-01-01 09:05:00.000
1900-01-01 09:11:00.000
1900-01-01 09:15:00.000
1900-01-01 09:16:00.000
1900-01-01 09:25:00.000
1900-01-01 09:26:00.000(所影响的行数为 6 行)t
------------------------------------------------------
1900-01-01 09:16:00.000
1900-01-01 09:26:00.000(所影响的行数为 2 行)