Highest Salary in each department

前端 未结 30 1509
没有蜡笔的小新
没有蜡笔的小新 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 23:13

    This will work if the department, salary and employee name are in the same table.

    select ed.emp_name, ed.salary, ed.dept from
    (select max(salary) maxSal, dept from emp_dept group by dept) maxsaldept
    inner join emp_dept ed
    on ed.dept = maxsaldept.dept and ed.salary = maxsaldept.maxSal
    

    Is there any better solution than this?

提交回复
热议问题