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

What is the beast way to write CTE in SQL Server ?

661


1 01 101 01010

1680


Explain what is public role in sql server?

683


How to get all stored procedures in sql server?

579


What is the difference between system objects and user objects?

794






Explain ranking functions?

707


Where sql server usernames and passwords are stored in a sql server?

577


Is INSTEAD OF trigger directly applicable to Table ?

658


What is the difference between update lock and exclusive lock?

584


How to rebuild master databse?

763


hi, the following are the outputs of sp_spaceused and sp_tempdbspace sp_spaceused ------------ database size unallocated size tempdb 77752.95 MB 28026.99 MB sp_tempdbspace ------------- database size spaceused tempdb 77752.945312 1.007812 the unused space in sp_spaceused is nearly 28 Gb and in sp_tempdbspace is nearly 76 Gb cany any one explain about this output and why its giving different results.

2572


What are binary string data types in ms sql server?

736


How to use go command in "sqlcmd"?

743


How to use wildcard characters in like operations in ms sql server?

698


How do you improve the performance of a SQL Azure Database?

123