#1111 - 无效使用组功能

时间:2011-01-18 17:21:17

标签: sql mysql mysql-error-1111

我正在使用以下查询来尝试获取每个项目中检索最大数量的幻灯片的总数(总和),但是我收到以下错误(#1111 - 无效使用组功能)。这是查询:

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

如果我删除SUM(),那么它可以工作,但是,我没有得到所有项目/幻灯片的准确总数。

提前感谢所有回复。

2 个答案:

答案 0 :(得分:4)

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

答案 1 :(得分:2)

您可以尝试使用以下内容:

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

您需要获得每个项目的最大值,然后您可以将所有项目相加。