Good Evening.
I'm trying to create a query that averages each product purchase Vs. the number of purchases to get the average amount purchased.
This includes three tables:
- CUSTOMER
- INVOICE
- LINE
I wrote this:
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;
I get an error at the second SELECT. I'm not sure why. I feel like I'm missing something very simple.
The actual error reads:
- "Syntax error in query expression '( SELECT [Sum([LINE]![LINE_NUMBER]*[LINE]![LINE_PRICE]) / [Count(INVOICE.INV_NUMBER)].'"
From the error I assume that somewhere in my expression things are not lining up, but I guess I don't understand enough about what is going on to know what exactly it is.