如何以下面的格式显示数据

时间:2015-04-25 12:36:23

标签: sql

我的表是:

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

1 个答案:

答案 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