Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Query failed (aggregate function or the GROUP BY clause) Expand / Collapse
Author
Message
Posted Thursday, November 15, 2012 3:20 AM


Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Monday, June 23, 2014 4:13 AM
Points: 73, Visits: 333
SAMPLE QUERY :



SELECT name, SUM(population)
FROM bbc
where population >1000


query failed and got error msg 8120

ERROR
"Column 'tt.dbo.bbc.name' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause."


I want to select name and corresponding sum (population) ..


help???








Post #1385037
Posted Thursday, November 15, 2012 3:23 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 6:52 AM
Points: 5,131, Visits: 4,918
If your using an aggregate function in the select, you need to put in a group by clause of all the columns which are not encased in an aggregate

SELECT name, SUM(population)
FROM bbc
WHERE population >1000
GROUP BY name




Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger

Post #1385040
Posted Thursday, November 15, 2012 3:34 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, May 14, 2014 7:43 AM
Points: 106, Visits: 174
SELECT name as Name, SUM(population) as Popualtion
FROM bbc
WHERE population >1000
GROUP BY name

If you aggregate the specific column then other remaining column in the select list should be group by...
Post #1385046
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse