SUM in grouped query?

G

Guest

Hi, I am having a problem. I havw three tables:
Subinventories - Names and IDs of locations
ccfile - All my widgets, numbers, quantities etc.
[Check in Items] - Items I have scanned
What I am trying to do is (Pseudocode SQL, sorry if it's not clear):
Go through [Check In Items]. Group by SubInv and bring in
Subinventories.Name where Subinventories.SubInv = [Check In Items].SubInv.
Then, Group by ItemNumber. For each ItemNumber I have nested in this report,
I want to have a field named ItemCount that is the SUM of ccfile.qty where
ccfile.itemnumber = [check in items].itemnumber and [ccfile].subinv = [check
in items].subinv

I have everything working except the SUM. I have been tooling around trying
to fix it, changed the joins, etc. and I am banging my head against the wall.
My current query is:

SELECT [Check In Items].id, [Check In Items].subinv, [Check In
Items].itemnumber, [Check In Items].lotcode, [Check In Items].matchedlot,
Ccfile.ItemDescription, Sum([ccfile].[Qty]) AS ItemCount, Subinventories.Name
FROM Subinventories INNER JOIN (Ccfile INNER JOIN [Check In Items] ON
Ccfile.ItemNumber = [Check In Items].itemnumber) ON
Subinventories.Subinventory = Ccfile.SubInv GROUP BY [ccfile].itemnumber;

I get an error:
You tried to execute a query that does not include the specified expression
'id' as part of an aggregate function.

Any ideas what I can do? Thanks for any help in advance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top