Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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 do I get Report Builder to generate a parameter that can be set by users viewing the report?

154


Can you explain the disadvantages/limitation of the cursor?

997


How can we migrate from SQL server to SQL Azure?

113


How to list all tables in the database using odbc_tables()?

1055


What is the default server name for sql server?

1185


Tell me extended events in sql server 2008?

1005


How to restore performance issues and how to check?

2012


How do I delete a sql server database?

1053


What does Master database contains?

1146


What is the downside of using udf?

1121


Is BCNF better than 2NF & 3NF? Why?

1060


Do you know how to make remote connection in database?

974


What are the types of normalization?

1038


Can we do dml on views?

972


explain different types of joins? : Sql server database administration

1000