O社区,你知道我怎么能选择department_ID,以及平均工资最高的部门的最低工资?或者如何消除' ORA-00934:group function not not not允许来这里'问题?我需要使用两个子查询吗?
到目前为止,这是我提出的,试图获得收入最高的部门的department_ID:
SELECT department_ID, MIN(salary
FROM employees
WHERE department_ID = (SELECT department_ID
FROM employees WHERE salary = MAX(salary));
谢谢,非常感谢您的协助。
答案 0 :(得分:0)
我无法对此进行测试,但它应该有效:
;WITH DepartmentsSalary AS
(
SELECT department_ID, AVG(Salary) AvgSalary, MIN(Salary) MinSalary
FROM employees
GROUP BY department_ID
)
SELECT department_ID, MinSalary
FROM ( SELECT department_ID, AvgSalary, MAX(AvgSalary) OVER() MaxSalary, MinSalary
FROM DepartmentsSalary) D
WHERE MaxSalary = AvgSalary
答案 1 :(得分:0)
您可以使用join(那么您只有一个子查询)
select e1.department_ID, min(e1.salary)
from employees e1
join (
select avg_query.department_ID, max(avg_query.avg_value)
from (
select department_ID, avg(salary) as avg_value
from employees
group by department_ID
) avg_query
) e2 on e2.department_ID = e1.department_ID
;