Unix Technical Forum

Error with SUM

This is a discussion on Error with SUM within the MySQL General forum forums, part of the MySQL category; --> Hi, The following query gives an error in MySql: SELECT SUM((SELECT SUM(a.id) FROM users AS b)) FROM users AS ...


Go Back   Unix Technical Forum > Database Server Software > MySQL > MySQL General forum

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-14-2008, 05:46 PM
e.krijgsman@student.utwente.nl
 
Posts: n/a
Default Error with SUM


Hi,

The following query gives an error in MySql:

SELECT SUM((SELECT SUM(a.id) FROM users AS b)) FROM users AS a

Error: #1111 - Invalid use of group function


I know the query doesn't really make sense and it is easy to rewrite it,
but the error occurred in some generated sql (this is obviously just a
stripped version of it) and I want to know what the reason for the error
is, so I can change the sql generator.

I already tried several fixes, and surprisingly, the following worked:

SELECT SUM((SELECT SUM(a.id*IF(b.id=0,1,1)) FROM users AS b)) FROM users AS a

To me, it seems that it fails, because the expression within the SUM part
is independant of the query in which it aggregates, or something like that.
Can anyone explain / clarify this and point me to where this restriction
is mentioned in the mysql documentation?



Thanks,
Erik-Jan Krijgsman


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:22 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com