create table test(num1 int,num2 int,num3 int,num4 int,num5 int,num6 int,num7 int)insert into test select 1,2,3,4,5,6,7unionselect 11,22,33,44,55,66,77--表中原始数据select * from test--行列互换with aa as(select *,ID=ROW_NUMBER() OVER (ORDER BY num1) from test)SELECT a2,a4FROM (select * from aa where ID=1) pUNPIVOT (a2 FOR a1 IN (num1,num2,num3,num4,num5,num6,num7))AS unpvt1,(select * from aa where ID=2) pUNPIVOT (a4 FOR a3 IN (num1,num7))AS unpvt2where a1=a3总结
以上是内存溢出为你收集整理的sqlserver 表行转列全部内容,希望文章能够帮你解决sqlserver 表行转列所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)