Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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). 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
287 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...