【问题标题】:Does Not Include Specified Expression as Part of Aggregate Function不包括指定表达式作为聚合函数的一部分
【发布时间】:2018-02-21 16:18:20
【问题描述】:

我已经研究过这个问题,但无法弄清楚我到底做错了什么。我在访问查询中有以下 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" 作为一部分 聚合函数。

Approval Status 字段的文本字符串显示为 Approved、Pending 或 Rejected。我只想返回 Pending 和 Pending 项目的计数,但我无法仅使用“Pending”作为标准。

【问题讨论】:

  • 您花时间问了这个问题。礼貌是我花时间为您提供的答案奖励我积分。除非你觉得它达不到你所需要的。只是说。

标签: ms-access ms-access-2010


【解决方案1】:

为简单起见,我将您的表达简化为:

select
      x
from y
group by
      x
having 
      x = "Pending";

问题是你似乎宁愿拥有这个:

select
      x
    , count(*) as PendingCount
from y
where 
    x = "Pending"
group by
    x

Having 用来表达更像

having count(*) > Q

这将告诉您在分组后发现哪些项目在原始数据中出现超过 Q 次。

where 将过滤器应用于选择的记录聚合之前。 have 将过滤器(必须声明为某种聚合过滤器,例如 count() )应用于聚合后的结果

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多