how to find nth highest salary

Answer Posted / nandkumar karlekar

Take this script and try u will get nth salary as you wish

create Table EmpTest
(
ID bigint,
Sal bigint
)
go
insert into emptest
values
(1,100)

insert into emptest
values
(2,200)

insert into emptest
values
(3,300)

insert into emptest
values
(4,400)

insert into emptest
values
(5,500)

insert into emptest
values
(6,600)
go
DECLARE @n bigint
--specify your nth salary
SET @n=3

select top 1 * from Emptest
where @n <= (select Count(*) from Emptest EE where EE.sal
>Emptest.sal)
order by sal desc

Is This Answer Correct ?    0 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Tell me what are the advantages of using stored procedures?

649


Do you know how to send email from database?

633


You want to be sure that queries in a database always execute at the maximum possible speed. To achieve this goal you have created various indexes on tables which other statement will keep the database in good condition?

626


What are partitioned views and distributed partitioned views?

705


Explain the etl (extraction, transformation, and loading)?

651






What are the parts of a function?

603


How do I find information about the install locations for the various instances running on a computer?

641


how can you attach more than 20 ldf files in sql server

1648


Define model database?

652


What is user-defined function?

661


How to run sql server 2005 books online on your local system?

611


Why and when do stored procedure recompile?

629


Why use view instead of a table?

623


Do you know what is openxml in sql server?

692


What is logshipping and its purpose?

636