Highest Salary in each department

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

    Not sure why no one has mentioned the Group By .... Having syntax. It specifically addresses these requirements.

    select EmpName,DeptId,Salary from EmpDetails group by DeptId having Salary=max(Salary);
    

提交回复
热议问题