Jump to content

Recommended Posts

I am using the following query in an attempt to get  total number(sum) of slides retrieving the max number from each project, however I am receiving the following error (#1111 - Invalid use of group function).

 

Projects              |    Slides

               

Air Stairs            |      15

Air Stairs            |      09

Baseball Game  |      22

Cargo                |      47

Cargo                |      31

 

Here's the query:

 

SELECT COALESCE(project,'Total') as Project, SUM(MAX(slides)) as Slides FROM projects_tbl WHERE date BETWEEN '2010-01-01' AND '2010-12-31' GROUP BY Project with ROLLUP

 

If I remove the SUM(), then the it works, however, I do not get an accurate total for all of the projects/slides.

 

Thanks in advance for any and all replies.

 

Link to comment
https://forums.phpfreaks.com/topic/224855-1111-invalid-use-of-group-function/
Share on other sites

When you use an aggregate function it takes all the rows in the group and applies the aggregate to them.  In the case of SUM() and your example data:

 

Air Stairs            |      15

Air Stairs            |      09

 

One would expect that the sum(slides) will be 24.  You can't nest aggregate functions as that doesn't make sense.  MAX() simply returns the largest value in the max'd column. 

 

Adding the Rollup is simply going to give you one more row where all the rows will be added together.

 

As fenways stated... what are you trying to do?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.