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

how many type of indexing in database?

1023


How you can get the list of largest tables in a database?

1069


What is 4nf in normalization form?

1063


Issues related in upgrading SQL Server 2000 to 2005 / 2008

1944


Do you know how to store and query spatial data?

1091


What is the use of partition by in sql server?

975


What is the cartesian product of the table?

1009


Do you know what is xpath?

1158


Explain about extended stored procedure?

995


Does dbcc checkdb requires db to be in single_user mode? : sql server database administration

1032


what do you understand by change data capture?

1082


How is SQL Azure different than SQL server?

225


between cast and convert which function would you prefer and why?

1021


What is meant by dirty read?

1043


How to create user messages with print statements in ms sql server?

1036