如何对计算字段求和
我想在这里问一个我认为对某些人来说很容易的问题。
好的,我有一个查询返回两个相关表的记录。 (一对多)
在此查询中,我有大约 3 到 4 个基于 2 个表中的字段的计算字段。
现在我想要一个用于名称的 group by 子句和一个 sum 子句来对计算字段求和,但最终会出现错误消息:
“您试图执行不属于聚合函数的查询”
所以我决定只运行没有总计的查询 *(即没有 group by 、 sum 等,,,) : 然后我创建了另一个查询来汇总我之前的查询。 (即使用 group by 子句表示名称,使用 sum 表示计算字段……这里没有计算)这很好(我过去常常这样做),但我不喜欢仅仅为了获得汇总总数而进行两个查询。他们是否有其他方式在设计视图中执行此操作并仅创建一个查询? 我将非常感激。
谢谢:
JM
I‘d like to ask I question that here that I think would be easy to some people.
Ok I have query that return records of two related tables. (One to many)
In this query I have about 3 to 4 calculated fields that are based on the fields from the 2 tables.
Now I want to have a group by clause for names and sum clause to sum the calculated fields but it ends up in error message saying:
“You tried to execute a query that is not part of aggregate function”
So I decided to just run the query without the totals *(ie no group by , sum etc,,,)
:
And then I created another query that totals my previous query. ( i.e. using group by clause for names and sum for calculated fields… no calculation here) This is fine ( I use to do this) but I don’t like having two queries just to get summary total. Is their any other way of doing this in the design view and create only one query?.
I would very much appreciate.
Thankyou:
JM
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来查询认为计算字段需要成为分组或其他内容的一部分。您可能需要研究子查询。
你能发布sql(之前和之后)吗?这将有助于了解问题所在。
Sounds like the query is thinking the calculated fields need to be part of the grouping or something. You might need to look into sub-querying.
Can you post the sql (before and after). It would help in getting an understanding of what the issue is.