SQL Group by problem

tanvirtonu

New member
Local time
Today, 03:25
Joined
Nov 3, 2008
Messages
3
Why cant I execute the following query in MsAccess-

Code:
SELECT SalesInvoice.ID, SalesInvoice.CustomerID, SalesInvoice.Commission, Sum(SalesInvoice.TotalAmount) AS SumOfTotalAmount
FROM SalesInvoice
GROUP BY SalesInvoice.CustomerID;
It says " you tried to execute a query that doesn't include the specified expresiion "ID" as part of an aggregate function "

But I can execute this-
Code:
SELECT CustomerID, Sum(TotalAmount) AS SumOfTotalAmount
FROM SalesInvoice
GROUP BY CustomerID;
Can't I select multiple columns in aggregation? PLs help me.
 
In a totals query, each field in the SELECT clause must either be aggregated in some way (Sum, Max, etc) or be included in the GROUP BY clause. You'll have to do one or the other to both ID and Commission.
 

Users who are viewing this thread

Back
Top Bottom