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

sql 将二行,并成一行

2013-03-10 
sql 将2行,并成一行。原表tableidtypeidinfotime11sohu2013-03-0522sina2013-03-0531sohu2013-03-0642sina2

sql 将2行,并成一行。
原表
table
id   typeid        info         time
1       1             sohu    2013-03-05
2       2             sina      2013-03-05
3       1             sohu     2013-03-06
4        2            sina       2013-03-06

想要的效果:
id   typeid        info         time             newid         newtypeid        newinfo     newtime
1       1             sohu    2013-03-05       3                    1                    sohu        2013-03-06
2       2             sina      2013-03-05       4                    2                     sina        2013-03-06

试了好久还是没弄出来,有人来帮帮忙么? sql table
[解决办法]

select * from tb a left join tb b on a.typeid=b.typeid and a.id+2=b.id
where (a.id-1)/2%2=0

[解决办法]
select * from tb a join tb b on a.typeid=b.typeid where a.id<b.id

热点排行