日期:2014-05-19  浏览次数:20385 次

时间分组,每2个一行
表格如下:
time  
9:05
9:10
9:11
9:15
9:19
....

想得到以下结果集

9:05   9:10
9:11   9:15
9:19

或者

9:05   9:10
9:11   9:15


------解决方案--------------------
declare @a table([time] varchar(10))
insert @a select '9:05 '
union all select '9:10 '
union all select '9:11 '
union all select '9:15 '
union all select '9:19 '

select t1,t2 from
(select [time] t1,id from (select [time],id=(select count(1) from @a where [time] <=a.[time]) from @a a) b where id%2=1) a1
left join
(select [time] t2,id from (select [time],id=(select count(1) from @a where [time] <=a.[time]) from @a a ) c where id%2=0) a2
on a1.id=a2.id-1