小编典典

#1111-无效使用组功能

sql

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

预先感谢您的所有答复。


阅读 241

收藏
2021-05-05

共1个答案

小编典典

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
2021-05-05