日期:2014-05-18 浏览次数:20650 次
select * from a t where exists ( select 1 from a where abs(datediff(millisecond,CreateDateTime,t.CreateDateTime)) <= 100 and id <> t.id )
------解决方案--------------------
--例如A表,有字段ID,CreateDateTime
--数据为
--1 2012-02-03 10:29:04.812
--2 2012-02-03 10:29:04.823
--3 2012-02-03 10:29:04.943
--4 2012-02-03 11:00:07.145
--5 2012-02-03 11:00:07.452
--6 2012-02-03 11:00:07.468
--7 2012-02-03 11:00:07.523
if OBJECT_ID('tb')is not null
drop table tb
go
create table tb (ID int,CreateDateTime varchar(50))
insert into tb
select 1, '2012-02-03 10:29:04.812' union all
select 2, '2012-02-03 10:29:04.823' union all
select 3, '2012-02-03 10:29:04.943' union all
select 4, '2012-02-03 11:00:07.145' union all
select 5, '2012-02-03 11:00:07.452' union all
select 6, '2012-02-03 11:00:07.468' union all
select 7, '2012-02-03 11:00:07.523'
select * from tb t where exists (select * from tb
where abs(datediff(millisecond,CreateDateTime,t.CreateDateTime)) <= 100 and id <> t.id
)
ID CreateDateTime
----------- --------------------------------------------------
1 2012-02-03 10:29:04.812
2 2012-02-03 10:29:04.823
5 2012-02-03 11:00:07.452
6 2012-02-03 11:00:07.468
7 2012-02-03 11:00:07.523
(5 行受影响)