Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2008
»
SQL Server 2008 - General
»
Query failed (aggregate function or the GROUP...
Query failed (aggregate function or the GROUP BY clause)
Rate Topic
Display Mode
Topic Options
Author
Message
sumith1andonly1
sumith1andonly1
Posted Thursday, November 15, 2012 3:20 AM
Valued Member
Group: General Forum Members
Last Login: Sunday, May 05, 2013 11:09 PM
Points: 66,
Visits: 260
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
anthony.green
anthony.green
Posted Thursday, November 15, 2012 3:23 AM
SSCertifiable
Group: General Forum Members
Last Login: Wednesday, June 05, 2013 2:40 AM
Points: 5,075,
Visits: 4,833
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
farooq.hbs
farooq.hbs
Posted Thursday, November 15, 2012 3:34 AM
SSC Journeyman
Group: General Forum Members
Last Login: Monday, March 18, 2013 1:44 AM
Points: 99,
Visits: 160
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 »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.