Highest Salary in each department

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

    Select empname,empid,Sal,DeptName from 
    (Select e.empname,e.empid,Max(S.Salary) Sal,D.DeptName, ROW_NUMBER() Over(partition by D.DeptName order by s.salary desc) Rownum
    from emp e inner join Sal S
    on e.empid=s.empid 
    inner join Dept d on e.Deptid=d.Deptid
    group by e.empname,e.empid,D.DeptName,s.Salary
    ) x where Rownum = 1
    

提交回复
热议问题