SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Find Nth Maximum from a Table...


Find Nth Maximum from a Table...

Author
Message
Hari.Sharma
Hari.Sharma
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1788 Visits: 455
Comments posted to this topic are about the item Find Nth Maximum from a Table...

Cheers,
Hari
Tips & Tricks for SQL BI Developers

Dhananjay Kulkarni-482726
Dhananjay Kulkarni-482726
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 6
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 ...
Madhivanan-208264
Madhivanan-208264
SSC Eights!
SSC Eights! (843 reputation)SSC Eights! (843 reputation)SSC Eights! (843 reputation)SSC Eights! (843 reputation)SSC Eights! (843 reputation)SSC Eights! (843 reputation)SSC Eights! (843 reputation)SSC Eights! (843 reputation)

Group: General Forum Members
Points: 843 Visits: 476
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



Madhivanan

Failing to plan is Planning to fail
Amulya Dutta
Amulya Dutta
SSC Rookie
SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)

Group: General Forum Members
Points: 38 Visits: 63
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search