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 do I get Report Builder to generate a parameter that can be set by users viewing the report?
Can you explain the disadvantages/limitation of the cursor?
How can we migrate from SQL server to SQL Azure?
How to list all tables in the database using odbc_tables()?
What is the default server name for sql server?
Tell me extended events in sql server 2008?
How to restore performance issues and how to check?
How do I delete a sql server database?
What does Master database contains?
What is the downside of using udf?
Is BCNF better than 2NF & 3NF? Why?
Do you know how to make remote connection in database?
What are the types of normalization?
Can we do dml on views?
explain different types of joins? : Sql server database administration