文章来源: http://ningoo.itpub.net/post/2149/281485

创建测试表,插入测试数据

 

)

 

select * from test 输出结果:



Sql Server 2005 PIVOT的行列转换应用实例

行列转换:

select id,name,[1],[2],[3],[4] from test 
pivot
(
sum(profile) for quarter in ([1],[2],[3],[4])
)
as pvt

 

转换后的结果:

Sql Server 2005 PIVOT的行列转换应用实例

假设需要转换的列不固定,可以使用下面方法:

 

pivot
(
SUM(profile) for quarter in (' + @S + ')
)
as pvt
')

相关文章:

  • 2021-11-20
  • 2021-09-16
  • 2022-12-23
  • 2022-12-23
  • 2021-11-25
猜你喜欢
  • 2021-12-06
  • 2021-10-11
  • 2022-02-09
  • 2021-06-30
相关资源
相似解决方案