1

假设我有下表,Table1

SIMULATION  STATEMENT_LINE                  PERIOD  OUTPUT_YTDIncStmt
0           A_1_a_Gross_Written_Premium     2012Q2  1362419134
0           A_Net_Earned_Premium            2012Q2  0
0           A_1_Gross_Earned_Premium        2012Q2  1362419134

有什么方法可以旋转 STATEMENT_LINE 列,所以我可以让它看起来像这样,而不是拥有所有的 A_1 等等。

PERIOD    [Gross Written Premium]    [Net Earned Premium]    [Gross Earned Premium]
2012Q2          1362419134                    0                     1362419134   

我想亲自指定要调用的列,而不仅仅是去掉“_”和“A”或“1”。

这样做的好方法是什么?

4

1 回答 1

1

你可以做这样的事情。

SELECT [Period],
    [A_1_a_Gross_Written_Premium] AS [Gross Written Premium],
    [A_Net_Earned_Premium] AS [Net Earned Premium],
    [A_1_Gross_Earned_Premium] AS [Gross Earned Premium]
FROM
  (
   SELECT [STATEMENT_LINE], [PERIOD], [OUTPUT_YTDIncStmt]
   FROM Table1
   ) AS Source

PIVOT
  (
   MAX(OUTPUT_YTDIncStmt)
   FOR STATEMENT_LINE IN ([A_1_a_Gross_Written_Premium], [A_Net_Earned_Premium], [A_1_Gross_Earned_Premium])
  ) AS PivotTable
于 2013-02-15T20:30:30.247 回答