Comments posted to this topic are about the item Find Nth Maximum from a Table...
This query is absolutely woking fine ...but if two employees r aving the same salary then it does not show correct result.. actuly it should show both employees for that rank.
this can be found using this query...:-->
select * from @table
where salary in (select top 1 salary from @table
where salary in (select top 3 salary from @Table order
by salary desc
order by salary
Looks complicated but not so ...
May be the old thread but I want to show you other approaches
Failing to plan is Planning to fail
top 5th Salary of every department
SELECT * FROM (
SELECT EMP_ID, DEPT_ID, SALARY, NAME
,RANK() OVER (PARTITION BY DEPT_ID ORDER BY SALARY DESC) AS RANKID
FROM EMP) A WHERE RANKID = 5
Viewing 4 posts - 1 through 3 (of 3 total)