lordfa9 Posted November 2, 2006 Share Posted November 2, 2006 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 More sharing options...
aspnetguy Posted November 2, 2006 Share Posted November 2, 2006 when using group by very column you select you have to group by as well Link to comment Share on other sites More sharing options...
lordfa9 Posted November 3, 2006 Author Share Posted November 3, 2006 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 More sharing options...
jesh Posted November 3, 2006 Share Posted November 3, 2006 So this means that all the rows not using the aggregrate function has to be added to the group by?You got it. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now