MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 14th, 2012, 11:08 PM
xbl1 xbl1 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2006
Posts: 365 xbl1 User rank is Sergeant (500 - 2000 Reputation Level)xbl1 User rank is Sergeant (500 - 2000 Reputation Level)xbl1 User rank is Sergeant (500 - 2000 Reputation Level)xbl1 User rank is Sergeant (500 - 2000 Reputation Level)xbl1 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 8 h 52 m 54 sec
Reputation Power: 22
Not contained in either an aggregate function or the GROUP BY

Hi;

i am trying sum all the price base on referenceNo, but i get the following error;

Column 'buyerName' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

my sql statment

select buyerName, id, category, productName, Sum(price) as "price", date, referenceNo from elena where referenceNo='d11';



Could anyone help ? Thanks

Last edited by xbl1 : December 14th, 2012 at 11:26 PM.

Reply With Quote
  #2  
Old December 15th, 2012, 05:11 AM
r937's Avatar
r937 r937 is online now
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,366 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 5 h 56 m 2 sec
Reputation Power: 4140
to understand this error message, follow along with this logic --

1. the SELECT clause contains an aggregate function, SUM(price)

2. the SELECT clause also contains several non-aggregate columns (six of them)

3. these other six columns must therefore also be in the GROUP BY clause but this is actually missing

does the error message make sense now?

put all six of the non-aggregate columns into the GROUP BY clause
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Reply With Quote
  #3  
Old December 15th, 2012, 03:27 PM
xbl1 xbl1 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2006
Posts: 365 xbl1 User rank is Sergeant (500 - 2000 Reputation Level)xbl1 User rank is Sergeant (500 - 2000 Reputation Level)xbl1 User rank is Sergeant (500 - 2000 Reputation Level)xbl1 User rank is Sergeant (500 - 2000 Reputation Level)xbl1 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 8 h 52 m 54 sec
Reputation Power: 22
Thanks a lot, i fix the problem already

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Not contained in either an aggregate function or the GROUP BY

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap