简体   繁体   English

来自三列的SQL SUM不起作用

[英]SQL SUM from three columns not working

I have an expression combining two queries, which works fine 我有一个结合两个查询的表达式,效果很好

SELECT FinalIncoming.ID, FinalIncoming.ProductCode, FinalIncoming.ProductName, 
  FinalIncoming.StandardCost, FinalIncoming.OnHand, FinalOutgoiing.Incoming, 
  FinalIncoming.Outgoing
FROM FinalIncoming INNER JOIN FinalOutgoiing ON FinalIncoming.ID = FinalOutgoiing.ID;

But whenever I try to SUM up the last three columns with: 但是每当我尝试对以下三列求和时:

Sum([FinalIncoming.OnHand]+[FinalIncoming.Outgoing]-[FinalOutgoiing.Incoming])

Access comes up with an error saying Your query does not include the specified expression 'ID' as part of an aggregate function. Access出现错误,提示Your query does not include the specified expression 'ID' as part of an aggregate function.

Does anyone know what I'm doing wrong here? 有人知道我在做什么错吗? I've tried rewriting the SUM expression in different ways, and with aliases, but it comes up with the same error. 我尝试用别名和别名以不同的方式重写SUM表达式,但是它出现了相同的错误。

FYI: I know the Outgoiing query is misspelled. 仅供参考:我知道Outgoiing查询的拼写错误。

the keyword in your error message is "as part of an aggregate" 错误消息中的关键字是“作为汇总的一部分”

ACCESS SQL requires all columns to be involved in an aggregation when you use the group by function. 当您使用group by函数时,ACCESS SQL要求所有列都必须包含在聚合中。

so your query would be: 因此您的查询将是:

SELECT FinalIncoming.ID, FinalIncoming.ProductCode, FinalIncoming.ProductName, 
      first(FinalIncoming.StandardCost) as firstCostValue, SUM(FinalIncoming.OnHand + FinalOutgoiing.Incoming - FinalIncoming.Outgoing) AS something
    FROM FinalIncoming INNER JOIN FinalOutgoiing ON FinalIncoming.ID = FinalOutgoiing.ID
GROUP BY FinalIncoming.ID, FinalIncoming.ProductCode, FinalIncoming.ProductName;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM