select * from (
select rank () over (partition by department_id order by salary desc) rn,
last_name, department_id, salary from employees )
where rn <= 3
=================== O R =======================
select FIRST_NAME, SALARY, D.DEPARTMENT_id
from employees E, departments D
where E.DEPARTMENT_ID=d.DEPARTMENT_ID
and (SELECT COUNT(DISTINCT(Salary)) FROM Employees
WHERE Department_Id = E.Department_Id AND Salary > E.Salary) < 3
ORDER by E.Department_Id, E.Salary DESC;
Tags:
Oracle SQL