One of the ways Oracle 11g works (as you noted your question), not mentioned in other answers, is an analyticmax() function. It allows the query to see values in other rows without losing details from the current row. For the human resources department, these are:
select EmpID, EmpName, EmpSalary, EmpDept
from (select EmpID, EmpName, EmpSalary, EmpDept,
max(EmpSalary) over () as max_sal
from employee where empdept = 'HR')
where EmpSalary = max_sal
EMPID EMPNAME EMPSALARY EMPDEPT
1 Steve 5000 HR
A similar query shows all employees with the maximum salary in their departments:
select EmpID, EmpName, EmpSalary, EmpDept
from (select EmpID, EmpName, EmpSalary, EmpDept,
max(EmpSalary) over (partition by EmpDept) as max_sal
from employee)
where EmpSalary = max_sal
EMPID EMPNAME EMPSALARY EMPDEPT
1 Steve 5000 HR
2 Robert 5000 Management
source
share