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
How will you monitor replication activity and performance? What privilege do you need to use replication monitor? : sql server replication
Tell me about builtinadministrator?
Why use cursor in sql server?
What are the components of sql server service broker?
Explain how many normalization forms?
How to connect Azure federated root database and apply federation in entity framework?
How to trouble shoot if unable to connect SQL Server
What are Row versions of DataRow?
What are the different types of collation sensitivity?
Explain the xml support sql server extends?
Do you know the isolation level that sql server support?
How to delete a database in ms sql server?
What are the five major components of a dbms?
If you want to send some data from access database to sql server database. What are different component of ssis will you use?
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