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 / gopi muluka

Execute below query against Adventureworks database

WITH CTE AS(
SELECT D.Name AS Department,E.EmployeeID,(RANK() OVER
(PARTITION BY D.Name ORDER BY MAX(Rate) DESC)) AS
EmployeeRank, MAX(Rate) AS HourlyRate
FROM [AdventureWorks].[HumanResources].[Employee] E
INNER JOIN HumanResources.EmployeePayHistory PH
ON E.[EmployeeID]=PH.[EmployeeID]
INNER JOIN HumanResources.EmployeeDepartmentHistory DH
ON E.EmployeeID=DH.EmployeeID
AND DH.EndDate IS NULL
INNER JOIN HumanResources.Department D
ON DH.DepartmentID=D.DepartmentID
GROUP BY D.Name,E.EmployeeID
)
SELECT * FROM CTE WHERE EmployeeRank=2
ORDER BY Department,EmployeeRank,EmployeeID

Is This Answer Correct ?    1 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is the different types of backups available in sql server? : Sql server database administration

882


Explain various data region available in ssrs with their use?

879


Can we add our custom code in ssis?

942


Do you think BCNF is better than 2NF & 3NF? Why?

1226


Can you roll back the ddl statement in a trigger?

915


how can you check the level of fragmentation on a table? : Sql server administration

921


What is the full form of ddl?

866


How many types of local tables are there in sql server?

889


New concepts of sql server 2005 use in your project.

2305


What does top operator do?

965


what is the difference between delete table and truncate table commands? : Sql server database administration

968


What does it mean if @@cursor_row returns a negative number?

943


Data is not being delivered to subscribers, what can be the possible reasons? : sql server replication

982


What is a data source or ds? : sql server analysis services, ssas

952


What happens if you are trying to access a schema not owned by you?

914