Highest Salary in each department

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

    The below query will display employee name with their respective department name in which that particular employee name is having highest salary.

    with T as
    (select empname, employee.deptno, salary
    from employee
    where salary in (select max(salary)
    from employee
    group by deptno))
    select empname, deptname, salary
    from T, department
    where T.deptno=department.deptno;
    

    I executed the above query successfully on Oracle database.

提交回复
热议问题