读书人

sql 将二行并成一行

发布时间: 2013-03-10 09:38:39 作者: rapoo

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

读书人网 >SQL Server

热点推荐