How to select the top 3 salaries of the department..?


 

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;

Post a Comment

Previous Post Next Post