首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

时间分组,每2个一行解决方案

2012-02-15 
时间分组,每2个一行表格如下:time9:059:109:119:159:19....想得到以下结果集9:059:109:119:159:19或者9:05

时间分组,每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

热点排行
Bad Request.