【问题标题】:SQL syntax error in query expression查询表达式中的 SQL 语法错误
【发布时间】:2013-04-21 21:26:16
【问题描述】:

我正在尝试运行此查询

select customerID, sum(OrderID)
from employee_T
where 2 < select(sum(OrderID) from employee_T)
group by customerID;

我想列出每个拥有超过 2 个订单的客户的客户 ID 和订单总数。

我在这一行得到语法错误

where 2 < select(sum(OrderID) from employee_T)

是不是因为2?s

【问题讨论】:

    标签: sql ms-access syntax


    【解决方案1】:

    我不熟悉 ms-access 语法,但这是您在常规 sql 中的做法:

    select customerID, count(OrderID)
    from employee_T
    group by customerID
    having count(orderID) > 2
    

    【讨论】:

    • having 允许使用像count 这样的聚合函数,因为它是在分组之后应用的。 where 在分组之前过滤行,having 在之后过滤它们。
    猜你喜欢
    • 2014-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多