declare @tb table(updata varchar(10)) insert @tb select '18:00' union select '18:01' union select '18:03' union select '18:05' union select '18:08' --测试 select [ID]=identity(int,1,1), * into # from @tbselect A.updata,B.updata from ( select * from # where ID%2=1 )A join ( select * from # where ID%2=0 )B on A.ID+1=B.ID where datediff(minute,convert(datetime,convert(datetime,A.updata)),convert(datetime,B.updata))=2drop table # --结果 /* updata updata ---------- ---------- 18:03 18:05(1 row(s) affected) */
insert @tb
select '18:00' union
select '18:01' union
select '18:03' union
select '18:05' union
select '18:08' --测试
select [ID]=identity(int,1,1),
*
into #
from @tbselect
A.updata,B.updata
from (
select * from # where ID%2=1
)A
join (
select * from # where ID%2=0
)B on A.ID+1=B.ID
where datediff(minute,convert(datetime,convert(datetime,A.updata)),convert(datetime,B.updata))=2drop table #
--结果
/*
updata updata
---------- ----------
18:03 18:05(1 row(s) affected)
*/