我试图使以下查询在 SQL Server 2008 中工作。返回一条错误消息,简单地说明“数据透视表附近的语法不正确”(这是最后)。谁能帮我找出错误?
SELECT * FROM (
(SELECT p_id, [InfoSec].[dbo].[tb_incidents_secureworks].[classification],
DATENAME(mm, occurrence) as [month]
FROM [InfoSec].[dbo].[tb_incidents_secureworks]
WHERE [InfoSec].[dbo].[tb_incidents_secureworks].[type] = 'Security Incident'
AND occurrence >= DATEADD(mm, DATEDIFF(mm,0,DATEADD(mm,-12,getdate())), 0)
AND occurrence < DATEADD(mm, DATEDIFF(mm,0,DATEADD(mm,0,getdate())), 0)
UNION ALL
SELECT p_id, [InfoSec].[dbo].[tb_incidents].[classification],
DATENAME(mm, occurrence) as [month]
FROM [InfoSec].[dbo].[tb_incidents]
WHERE (occurrence >= DATEADD(mm, DATEDIFF(mm,0,DATEADD(mm,-12,getdate())), 0)
AND occurrence < DATEADD(mm, DATEDIFF(mm,0,DATEADD(mm,0,getdate())), 0)))
AS SourceTable
PIVOT (
COUNT(p_id)
FOR [month] in ([August],[September],[October],[November],[December],[January],[February],[March],[April],[May],[June],[July])
) AS PivotTable