我目前有一个表,其中包含按月和行的数据作为列
Region Location Year Month FY15 Overtime Wages
East Philly 2015 11 100
East Philly 2015 12 105
West NYC 2015 11 87
West NYC 2015 12 94
我需要这个看起来像:
Region Location [OT Spend 2015-11] [OT Spend 2015-12] ...etc...
East Philly 100 105 ...etc...
West NYC 87 94 ...etc...
我试过这个,但不管我做了什么改变,它都会经常出错(不值得写错误):
SELECT
PC
, 'OT Spend '&Format(Year & '-' & [Month #],'yyyy-mm')
FROM
(select
PC
, Year
, [Month #]
, [FY15 Overtime Wages]
from
[OT Extract]) p
PIVOT
(
Sum([FY15 Overtime Wages])
FOR [FY15 Overtime Wages]
IN ('OT Spend '&Format(Year & '-' & [Month #],'yyyy-mm'))
) piv;
任何想法或简单,因为我有另一个数据透视表来创建完全相同但不同的列。