“乔的经理想要有关按部门分组的员工的信息,
按性别分组,此外按部门和性别组合。仅列出
在部门中以字母D开头的人员
列出部门,性别,工资总额,最低工资和最高工资
薪水。”

所以基本上,我需要3个小组。
但是我似乎无法将GROUP BY WorkDept和Sex结合在一起。

这对我不起作用:

    SELECT WORKDEPT, SUM(SALARY) AS SALARY_SUM, MIN(SALARY) AS MIN_SALARY,
  MAX(SALARY) AS MAX_SALARY
  FROM EMPLOYEE
  WHERE WORKDEPT LIKE 'D%'
      GROUP BY CUBE(WORKDEPT, SEX);


谢谢!

最佳答案

我认为其他人是正确的,因为您可能使问题变得过于复杂。但是,如果打算使用cube,请尝试with cube。像这样...

select
    WORKDEPT,
    sum(SALARY) as SALARY_SUM,
    min(SALARY) as MIN_SALARY,
    max(SALARY) as MAX_SALARY

from EMPLOYEE

where WORKDEPT LIKE 'D%'

group by WORKDEPT, SEX
with cube

10-08 13:31