表格如下:
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

解决方案 »

  1.   

    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 [time],id=identity(int,1,1) into #tmp from @a order by  [time]
    select t1,t2 from 
    (select [time] t1,id from #tmp where id%2=1) a1
    left join
    (select [time] t2,id from #tmp where id%2=0) a2
    on a1.id=a2.id-1drop table #tmp
      

  2.   

    create table test(num nvarchar(10))
    insert into test 
    select '1'
    union all select '2'
    union all select '3'
    union all select '4'
    union all select '5'
    union all select '6'select id=identity(int,1,1),num=num into #t from testselect id=identity(int,1,1),num=num into #t1 from #t where id%2=1
    select id=identity(int,1,1),num=num into #t2 from #t where id%2=0
    select num1=#t1.num,num2=#t2.num from #t1,#t2 where #t1.id=#t2.id
    drop table #t
    drop table #t1
    drop table #t2
    drop table test
      

  3.   

    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