【发布时间】:2023-02-07 22:55:52
【问题描述】:
我有一个简单的SQL,结果是员工的基本信息。
select emp_name, emp_firstname, emp_location, emp_salary from employees e
where e.emp_location = 'XYZ'
现在,如果该地点所有员工的工资总和超过 1.000.000 欧元,我只想获得上述 SQL 的结果。否则结果应该为 NULL。
我创建了一个 select 语句,它确实分析了所有员工的总和并返回 NULL 或超过 1.000.000 EUR 的 SUM 值:
select sum(emp_salary) from employees e
where e.emp_location = 'XYZ'
having sum(emp_salary) > 1000000
当我现在尝试组合这两个 SQL 时:
select emp_name, emp_firstname, emp_location, emp_salary from employees e
where e.emp_location = 'XYZ'
having sum(emp_salary) > 1000000
我收到错误 ORA-00937 not a single-group group function
【问题讨论】:
-
您选择了非聚合字段,但没有使用
GROUP BY子句。那是你的问题。