我的表是:
Id Name Add
1 a A
2 b B
3 c C
4 d D
我想将其替换为:
Id Name Add Id2 Name2 Add2
1 a A 2 b B
3 c C 4 d D
答案 0 :(得分:1)
使用下面的查询
Select LTable.id,LTable.Name,LTable.[Add],
RTable.id,RTable.Name,RTable.[Add]
from
(
Select Row_Number()over ( order by id)as fldkey,id,name , [Add]
from TableName
where id % 2 <> 0
) as LTable INNER JOIN
(
Select Row_Number()over ( order by id)as fldkey,id,name , [Add]
from TableName
where id % 2 = 0
) as RTable
on LTable.fldKey = RTable.fldKey