4

我正在使用以下查询来尝试获取从每个项目中检索最大数量的幻灯片总数(总和),但是我收到以下错误(#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(),那么它可以工作,但是,我没有得到所有项目/幻灯片的准确总数。

在此先感谢您的任何和所有回复。

4

2 回答 2

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
于 2011-01-18T17:32:42.440 回答
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)

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

于 2011-01-18T17:30:42.557 回答