1

以下查询在 MS Access 中运行良好,但我实际上只想获取 Main Project 字段加上 Name 的计数。就像是:

SELECT Sheet1.[Main project], Count(Sheet1.[Name]) AS Total

当我这样做时,我收到以下错误:

“您尝试执行的查询不包含指定表达式‘主项目’作为聚合函数的一部分’

我在加入中做错了吗?知道什么是不正确的吗?

SELECT Sheet1.[Main project], Sheet1.[Main link], Sheet1.[Name]
FROM Sheet1
INNER JOIN Sheet1 AS Sheet1_1 

ON (Sheet1.[Main link] = Sheet1_1.[Main link]
AND Sheet1.[Main project] = Sheet1_1.[Main project])

WHERE Sheet1_1.[Name] ='0.4 Rollout plan approved'
AND Sheet1_1.[%compl#] = 100
AND (Sheet1_1.[Task class] <> '***Sammelvorgang' AND Sheet1_1.[Task class] <> '' AND  Sheet1_1.[Task class] <> 'M D-Muster')

AND Sheet1.[Main project] = 'AUDI AG, Ingolstadt'
AND (Sheet1.[Task class] <> '***Sammelvorgang' AND Sheet1.[Task class] <> '' AND  Sheet1.[Task class] <> 'M D-Muster')
AND (Sheet1.[Name] NOT LIKE '0.*' AND Sheet1.[Name] NOT LIKE '1.*')
AND Sheet1.[Start] < DateAdd("d",-7,Now())
4

1 回答 1

1
SELECT Sheet1.[Main project], Count(Sheet1.[Name]) AS Total
    FROM Sheet1
    GROUP BY Sheet1.[Main project]

Count()仅当您想要表中所有内容的总数时,聚合函数才会自动工作。如果你想把它分解成更具体的分组,你需要一个GROUP BY语句来告诉数据库如何分解它。

将其集成到更大的查询中应该不是问题:只需注意GROUP BY子句位于子句之后WHERE;因此你应该在最后添加它。

于 2012-12-18T11:22:15.270 回答