MS ACCESS查询:不是聚合函数的一部分

时间:2013-04-24 22:47:44

标签: ms-access expression aggregate

MSACCESS查询:

我有一个追加查询,从2个表(右连接)中提取字段。我想添加一个表达式,将一个字段中的值乘以表单上的值。查询工作正常,直到我添加计算的表达式,但错误是另一个(不相关的)字段不是聚合函数的一部分。如果我删除该字段,它将会抱怨另一个字段 - 除非我删除计算出的表达式,否则它会一直打开。

使用:

INSERT INTO quote_items ( quote_unique, quote_group_a, quote_group_b, unique_product_id, DESCRIPTION, nat_price, markup, sell_price )
SELECT [Forms]![frmQUOTE].[txtQUOTE_NO] AS quote_unique, [Forms]![frmQUOTE].[cmbGROUP_A] AS quote_group_a, [Forms]![frmQUOTE].[txtGROUP_B] AS quote_group_b, ASSY_CHILDREN.UPI, ASSY_CHILDREN.DESCRIPTION, [A - MASTER PRODUCT LIST].[NAT PRICE], [Forms]![frmQUOTE]![txtMU] AS markup, ([NAT PRICE]*[markup])+[NAT PRICE] AS sell_price
FROM [A - MASTER PRODUCT LIST] RIGHT JOIN ASSY_CHILDREN ON [A - MASTER PRODUCT LIST].[UNIQUE PART NO] = ASSY_CHILDREN.PARENT_UPI
WHERE ((([A - MASTER PRODUCT LIST].[UNIQUE PART NO])=[Forms]![frmQUOTE].[cmbPART_TO_ADD]));

不起作用:

INSERT INTO quote_items ( quote_unique, quote_group_a, quote_group_b, unique_product_id, DESCRIPTION, QTY, nat_price, markup, sell_price )
SELECT [Forms]![frmQUOTE].[txtQUOTE_NO] AS quote_unique, [Forms]![frmQUOTE].[cmbGROUP_A] AS quote_group_a, [Forms]![frmQUOTE].[txtGROUP_B] AS quote_group_b, ASSY_CHILDREN.UPI, ASSY_CHILDREN.DESCRIPTION, Sum([QTY]*[Forms]![frmQUOTE]![txtQTYTOADD]) AS expr1, [A - MASTER PRODUCT LIST].[NAT PRICE], [Forms]![frmQUOTE]![txtMU] AS markup, ([NAT PRICE]*[markup])+[NAT PRICE] AS sell_price
FROM [A - MASTER PRODUCT LIST] RIGHT JOIN ASSY_CHILDREN ON [A - MASTER PRODUCT LIST].[UNIQUE PART NO] = ASSY_CHILDREN.PARENT_UPI
WHERE ((([A - MASTER PRODUCT LIST].[UNIQUE PART NO])=[Forms]![frmQUOTE].[cmbPART_TO_ADD]));

添加了表达式:

expr1: Sum([QTY]*[Forms]![frmQUOTE]![txtQTYTOADD])

奇怪的是它抱怨UPI不是聚合的一部分,但如果删除了这个计算的表达式(与UPI无关),则返回UPI就好了。

1 个答案:

答案 0 :(得分:0)

我的建议:首先简单地删除Sum()并使用...

expr1: [QTY]*[Forms]![frmQUOTE]![txtQTYTOADD]

......或者只是......

expr1: [Forms]![frmQUOTE]![txtQTYTOADD]

测试您的代码,看看它是否能为您提供所需的结果。如果没有,那么edit您的问题就会向我们展示一些有代表性的示例数据以及您希望实现的示例。