Oracle
 sql >> Database >  >> RDS >> Oracle

ORA-00934:funzione di gruppo non consentita qui || Selezionando MIN (Salario) del reparto più pagato

Non posso testarlo, ma dovrebbe funzionare:

;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