Unpivot 每月计划数据

Unpivot monthly plan data

如何转换此输入

Product | CC | 2017_11 | 2017_12
Product X | 220 | 100 | 200 

变成这样的东西?

Product | CC | Month |EUR
Product X | 220 | 2017_11 | 100
Product X | 220 | 2017_12 | 200

我用 UNPIVOT 尝试过,但无法将句点 headers 放入行中。 这是我的样本

    SELECT Product, [month] FROM 

(SELECT Product
            [2017_11],
            [2017_12]
 FROM
[MONTHLY_REPORTING].[dbo].[FP_2017_2018_V2_revenue_import]

)
as input

UNPIVOT 
    ([month] FOR month_x IN ([2017_11], [2017_12])) as U1

您需要 UNPIVOT 值,在您的情况下 EUR,对于 month 在您的 headers

 SELECT Product, [month], [EUR] 
FROM (
    SELECT
        Product
        ,[2017_11]
        ,[2017_12]
     FROM [MONTHLY_REPORTING].[dbo].[FP_2017_2018_V2_revenue_import]
) as input
UNPIVOT (
    [EUR] FOR [month] IN ([2017_11], [2017_12])
) as U1