how to find nth highest salary
Answer Posted / vidit
DECLARE @SQL VARCHAR(2000), @N INT
SET @N = 5
SET @N = @N - 1
SET @sql = 'select top 1 salary from ABC where salary not
in ( SELECT TOP ' + CAST(@n AS VARCHAR(100)) + ' salary
FROM ABC order by salary desc ) ' + ' order by salary desc '
SELECT @SQL
EXEC @SQL
| Is This Answer Correct ? | 4 Yes | 1 No |
Post New Answer View All Answers
Explain the advantages of merge replication?
What is the difference between createstatement and preparedstatement?
Explain what are the basic functions for master, msdb, model, tempdb databases?
What are data driven subscriptions?
What are the advantages of sql azure?
What is an execution plan?
What is subquery in sql?
Define outer join?
What is the use of “join” in sql server?
Is it possible for a stored procedure to call itself or recursive stored procedure?
What is a field in a table?
How to compare the top two records using sql?
What is @@rowcount in sql?
What is filter index?
What is usually the first word in a sql query?