Highest Salary in each department

前端 未结 30 1519
没有蜡笔的小新
没有蜡笔的小新 2021-01-30 22:16

I have a table EmpDetails:

DeptID      EmpName   Salary
Engg        Sam       1000
Engg        Smith     2000
HR          Denis     1500
HR                  


        
30条回答
  •  暖寄归人
    2021-01-30 22:52

    SELECT Employee_ID
         , First_name
         , last_name
         , department_id
         , Salary 
    FROM (SELECT Employee_ID
               , First_name
               , last_name
               , department_id
               , Salary
               , MAX(salary) OVER (PARTITION BY department_id) dept_max_sal
          FROM EMPLOYEES) AS Emp
    WHERE salary = dept_max_sal;
    

提交回复
热议问题