请教大家这种转置怎么写?
客户字段A字段B字段C
A102030
B405060
B708090
客户字段类型值
A字段A10
A字段B20
A字段C30
B字段A40
B字段B50
B字段C60
B字段A70
B字段B80
B字段C90
谢谢指点。
[解决办法]
select 客户,'字段A' as 字段类型,字段A as 值 from tbunion allselect 客户,'字段B' as 字段类型,字段B as 值 from tbunion allselect 客户,'字段C' as 字段类型,字段C as 值 from tb
[解决办法]
declare @T table([客户] varchar(1),[字段A] int,[字段B] int,[字段C] int)insert @Tselect 'A',10,20,30 union allselect 'B',40,50,60 union allselect 'B',70,80,90select [客户],'[字段A]' as 字段类型,[字段A] as 值 from @T union allselect [客户],'[字段B]' as 字段类型,[字段B] from @T union allselect [客户],'[字段C]' as 字段类型,[字段C] from @T order by 1,3/*客户 字段类型 值---- ------- -----------A [字段A] 10A [字段B] 20A [字段C] 30B [字段A] 40B [字段B] 50B [字段C] 60B [字段A] 70B [字段B] 80B [字段C] 90*/