,我發現了以下錯誤:SQL服務器:透視功能錯誤
Msg 102, Level 15, State 1, Line 2
Incorrect syntax near '('.
當執行此查詢:
SELECT
'Average Total Comp' AS AverageTotalComp,
[2016], [2015], [2014]
FROM
(SELECT
DATEPART(yyyy, [Fiscal Year End Date]),
[Total Compensation ($)]
FROM
dbo.MDexec e) AS SourceTable
PIVOT
(AVG([Total Compensation ($)])
FOR DATEPART(yyyy, [Fiscal Year End Date])
IN ([2016], [2015], [2014])) AS PivotTable;
我試圖同時使用YEAR
和DATEPART
。錯誤是引用第二個DATEPART
上的開頭括號。
你打我吧。 – Eli