Find top Nth employee from each department in terms of
salary?

Answer Posted / chandra sekhar

CREATE A EMPLOYEES TABLE WITH THE COLUMNS
EMPLOYEEID,EMPLOYEENAME,DEPARTMENT,SALARY
AND INSERT THE RECORDS INTO THE TABLE

with cte
as (
select dense_RANK() over(partition by department order by salary desc) as Rank,
employeeID,employeename,department,salary from
Employees)
select x.employeeID,
x.employeename,
x.department,
x.salary,
x.rank
from cte x
where x.Rank=2
order by x.Salary


NOTE:here i am finding 2nd highest salary from the each department

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How will you monitor replication activity and performance? What privilege do you need to use replication monitor? : sql server replication

564


Tell me about builtinadministrator?

570


Why use cursor in sql server?

560


What are the components of sql server service broker?

516


Explain how many normalization forms?

588






How to connect Azure federated root database and apply federation in entity framework?

87


How to trouble shoot if unable to connect SQL Server

1488


What are Row versions of DataRow?

618


What are the different types of collation sensitivity?

565


Explain the xml support sql server extends?

634


Do you know the isolation level that sql server support?

535


How to delete a database in ms sql server?

569


What are the five major components of a dbms?

520


If you want to send some data from access database to sql server database. What are different component of ssis will you use?

513


I have all the primary data files, secondary data files as well as logs. Now, tell me can I still restore the database without having a full backup? : sql server database administration

690