alter table tablename add id int identity(1,1)
go
select datediff(ms,a.time,b.time) as '相减'
from tablename a
inner join tablename b
on a.id=b.id-1
where a.id % 2 =1
and b.id % 2 = 0
go
select datediff(ms,a.time,b.time) as '相减'
from tablename a
inner join tablename b
on a.id=b.id-1
where a.id % 2 =1
and b.id % 2 = 0
所以条件:
on a.id=b.id-1
where a.id % 2 =1
and b.id % 2 = 0
就通不过.
insert into #t select '2005-06-01 08:30'
insert into #t select '2005-06-01 12:30'
insert into #t select '2005-06-01 14:30'
insert into #t select '2005-06-01 18:30'
insert into #t select '2005-06-01 20:30'select
max(c.time)-min(c.time)
from
(select
a.time,num = count(*)
from
#t a,
#t b
where
a.time >= b.time
group by
a.time) c
group by
(c.num+1)/2
having max(c.time)<>min(c.time)
(select
a.time,num = count(*)
from
#t a,
#t b
where
a.time >= b.time
group by
a.time) c
select id=identity(int,1,1),a_time into #tmp from tb--查询
select * from #tmp
select a_time-(select a_time from #tmp where id=a.id-1) from #tmp a where id%2=0--删除临时表