请问怎么查询出一个表里全部时间间隔小于100毫秒的记录?
例如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
需要得到的结果为
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
想看看有多少操作是属于并发的,或者有没有其他的方法?谢谢!
[解决办法]
上面有问题
select * from a twhere 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.523if OBJECT_ID('tb')is not null drop table tbgo create table tb (ID int,CreateDateTime varchar(50))insert into tb select 1, '2012-02-03 10:29:04.812' union allselect 2, '2012-02-03 10:29:04.823' union allselect 3, '2012-02-03 10:29:04.943' union allselect 4, '2012-02-03 11:00:07.145' union allselect 5, '2012-02-03 11:00:07.452' union allselect 6, '2012-02-03 11:00:07.468' union allselect 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.8122 2012-02-03 10:29:04.8235 2012-02-03 11:00:07.4526 2012-02-03 11:00:07.4687 2012-02-03 11:00:07.523(5 行受影响)