晚安。
我正在尝试创建一个平均每个产品购买量的查询。购买平均金额的购买次数。
这包括三个表:
我写了这个:
SELECT CUSTOMER.CUS_CODE, CUS_FNAME+" "+CUS_LNAME AS Name, CUSTOMER.CUS_BALANCE,
Sum([LINE]![LINE_NUMBER]*[LINE]![LINE_PRICE]) AS Total_purchases,
Count(INVOICE.INV_NUMBER) AS Number_of_purchases,
(
SELECT [Sum([LINE]![LINE_NUMBER]*[LINE]![LINE_PRICE]) /
[Count(INVOICE.INV_NUMBER)]
FROM INVOICE, LINE
WHERE INVOICE.INV_NUMBER = LINE.INV_NUMBER
) AS Average_purchase_amount
FROM CUSTOMER, INVOICE, LINE
WHERE CUSTOMER.CUS_CODE = INVOICE.CUS_CODE AND INVOICE.INV_NUMBER = LINE.INV_NUMBER
GROUP BY CUSTOMER.CUS_CODE, CUS_FNAME+" "+CUS_LNAME, CUSTOMER.CUS_BALANCE;
我在第二个SELECT时遇到错误。我不知道为什么。我觉得我错过了很简单的事情。
实际错误为:
从错误中我认为在我的表达中的某些地方没有排队,但我想我不知道究竟发生了什么事情。
答案 0 :(得分:1)
有不平衡的括号。要么每个都在括号或整个等式中:
SELECT [Sum([LINE]![LINE_NUMBER]*[LINE]![LINE_PRICE])] / [Count(INVOICE.INV_NUMBER)]
- 或 -
SELECT [Sum([LINE]![LINE_NUMBER]*[LINE]![LINE_PRICE]) / Count(INVOICE.INV_NUMBER)]
尝试加入你的表格。像这样:
FROM INVOICE
INNER JOIN CUSTOMER ON CUSTOMER.CUS_CODE = INVOICE.CUS_CODE
INNER JOIN LINE ON LINE.INV_NUMBER =INVOICE.INV_NUMBER