Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
varalaruu
Starting Member
1 Post |
Posted - 2008-11-19 : 11:34:47
|
| write the query of to find the n th maximum salary? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-19 : 11:41:40
|
| SELECT SalaryFROM(SELECT ROW_NUMBER() OVER(ORDER BY Salary) AS Seq,Salary FROM Table)tWHERE t.Seq=@N |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-19 : 12:23:45
|
| also see thishttp://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/find-nth-maximum-value.aspx |
 |
|
|
sunsanvin
Master Smack Fu Yak Hacker
1274 Posts |
Posted - 2008-11-20 : 01:17:58
|
| Fairly Interview QuestionArnavEven you learn 1%, Learn it with 100% confidence. |
 |
|
|
karthickbabu
Posting Yak Master
151 Posts |
Posted - 2008-11-20 : 05:13:22
|
| Give Nth position instead of 'N'SELECT * FROM TableName T1 WHERE (N-1) = (SELECT COUNT(DISTINCT(T2.Salary)) FROM TableName T2 WHERE T2.Salary > T1.Salary)==================================================== you realize you've made a mistake, take immediate steps to correct it. |
 |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2008-11-20 : 05:19:39
|
| ROW_NUMBER() is probably the most efficient way as Visakh suggested.Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
|
|
|
|