Jump to content

Cannot run SQL statement


lordfa9

Recommended Posts

I have the following SQL statementSELECT Stock.Itemcode, Sum(Stock.QTY) AS TOTAL_QUANTITYFROM StockGROUP BY Stock.Itemcode;This SQL works fine, however when I add itemname to the statement:SELECT Stock.Itemcode, Stock.Itemname, Sum(Stock.QTY) AS TOTAL_QUANTITYFROM StockGROUP BY Stock.ITEM; It gives me the error ‘You tried to execute a query that does not include the specified expression ‘itemname’ as part of an aggregate function’. Background: there may be more than one entry of the same item in the table (it’s a result of the merging of a few tables) and the first statement is to calculate the total number of each type of stock

Link to comment
Share on other sites

Ooo so its like such:

SELECT Stock.Item, Stock.Itemname, Sum(Stock.QTY) AS TOTAL_QUANTITYFROM StockGROUP BY Stock.ITEM, Stock.Itemname;

So this means that all the rows not using the aggregrate function has to be added to the group by?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...