September 29, 2007 at 11:57 pm
Comments posted to this topic are about the item Find Nth Maximum from a Table...
October 21, 2007 at 11:25 pm
Hi,
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 ...
September 19, 2008 at 6:59 am
May be the old thread but I want to show you other approaches
http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/find-nth-maximum-value.aspx
Failing to plan is Planning to fail
August 17, 2009 at 11:49 pm
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)
You must be logged in to reply to this topic. Login to reply