我已经研究过这个问题,但无法弄清楚我做错了究竟是什么。我在Access Query中有以下SQL代码。
SELECT [Age and Info Report].[Approval Status]
FROM [Age and Info Report]
GROUP BY [Age and Info Report].[Approval Status]
HAVING ((([Age and Info Report].[Approval Status])="Pending"));
我一直收到这个错误:
您尝试执行不包含指定的查询 表达'[年龄和信息报告]。[审批状态] =“待定”作为一部分 一个集合函数。
“审批状态”字段的文本字符串显示为“已批准”,“待处理”或“已拒绝”。我只想返回Pending和Pending项目的计数,但我不能仅仅使用“Pending”作为标准。
答案 0 :(得分:0)
为简单起见,我已将表达减少到:
select
x
from y
group by
x
having
x = "Pending";
问题是你似乎更喜欢这个:
select
x
, count(*) as PendingCount
from y
where
x = "Pending"
group by
x
习惯于说更像
的事情having count(*) > Q
这将告诉您在分组后,哪些项目在原始数据中发现的次数超过Q次。
其中将过滤器应用于之前选择的记录。 将聚合后的结果应用过滤器(必须将其称为某种聚合过滤器,例如count())。