--创建测试表
CREATE TABLE #a(lb VARCHAR(2),A
MONEY,B MONEY,C MONEY)
INSERT INTO #a( lb,A,B,C) VALUES
('X1',1,2,3)
INSERT INTO #a( lb,A,B,C) VALUES
('X2',4,5,6)
INSERT INTO #a( lb,A,B,C) VALUES
('X3',7,8,9)
INSERT INTO #a( lb,A,B,C) VALUES
('X4',10,11,12)
INSERT INTO #a( lb,A,B,C) VALUES
('X5',13,14,15)
--查一下
SELECT * FROM #a
--90度旋转
SELECT * FROM
(
SELECT [ABC],lb,[data] FROM
(SELECT lb, A, B, C FROM #a )
p
UNPIVOT
([data] FOR [ABC] IN (A, B, C))AS
unpvt
) T
PIVOT
(SUM([data]) FOR
lb in ([X1],[X2],[X3],[X4],[X5]))AS pt
DROP TABLE #a