如何将列转换为表格的行,包括oracle中的标题。
slno id name
1 A XXXX
2 B YYYY
3 C ZZZZ
4 D MMMM
我想输出
col1 col2 col3 col4
slno 1 2 3 4
id A B C D
name XXXX YYYY ZZZZ MMMM
答案 0 :(得分:0)
我已经在ms sql上工作了,可能这应该有帮助,你可以根据oracle进行一些修改
select * from(
select slno,id,name from [tablename]
) abc
pivot
(
slno,id,name for [Group]
in (col1,col2,col3)
)
as pvt
我正在使用冒险作品2012数据库 我在这里使用它
select * from(
select [CountryRegionCode],[Group],[SalesYTD] from [Sales].[SalesTerritory]
) abc
pivot
(
sum([SalesYTD]) for [Group]
in ([North America], [Europe],[Pacific])
)
as pvt