Calculating maximum salary of employee in each department

CGN007
Posted by CGN007 under Sql Server category on | Points: 40 | Views : 1473
DDL

  create table EmployeeMas
(Firstname varchar(10),
Lastname varchar(10),
sal float,
Department varchar(10)
)


DML to find out the maximum salary of employee in each department

SELECT Firstname,Lastname,Department,sal 
FROM
(
SELECT Firstname,Lastname,Department,sal ,
ROW_NUMBER() OVER(PARTITION BY Department ORDER BY sal DESC)AS rownumber
FROM EmployeeMas
)
AS t WHERE rownumber=1

Comments or Responses

Login to post response