Oracle
 sql >> Base de Dados >  >> RDS >> Oracle

ORA-00934:Função de grupo não permitida aqui || Selecionando MIN(Salary) do departamento mais bem pago


Eu não posso testar isso, mas deve funcionar:
;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