我无法弄清楚我的查询丢失了什么:
PARAMETERS StartDate DateTime;
SELECT Count(GRANTS.[Grant Identified]) AS [CountOfGrant Identified]
FROM GRANTS
WHERE GRANTS.[Grant Identified]=Yes AND (GRANTS.[Identified Date] >= StartDate)
PIVOT ((Year(GRANTS.[Identified Date])*12 + Format(GRANTS.[Identified Date], "mm")) - (Year(StartDate)*12 + Format(StartDate, "mm")) + 1)
IN (1,2,3,4,5,6,7,8,9,10,11,12);
我的头脑已经变得麻木了,我已经找到了我能找到的所有解决方案(通常是’ != '
问题)。
感谢。
答案 0 :(得分:1)
PIVOT子句告诉我们您正在尝试进行交叉表查询,但您没有TRANSFORM子句。 Access SQL中交叉表查询的一般形式是
TRANSFORM AggregateFunction(ValueField) AS whatever
SELECT RowHeadingFields
FROM TableName
GROUP BY RowHeadingFields
PIVOT ColumnHeadingField [IN (ValueList)]
因此您的查询需要看起来更像这样:
PARAMETERS StartDate DateTime;
TRANSFORM Count(GRANTS.[Grant Identified]) AS [CountOfGrant Identified]
SELECT GRANTS.[Grant Identified]
FROM GRANTS
WHERE GRANTS.[Grant Identified]=Yes AND (GRANTS.[Identified Date] >= StartDate)
GROUP BY GRANTS.[Grant Identified]
PIVOT ((Year(GRANTS.[Identified Date])*12 + Format(GRANTS.[Identified Date], "mm")) - (Year(StartDate)*12 + Format(StartDate, "mm")) + 1)
IN (1,2,3,4,5,6,7,8,9,10,11,12);