select dept_no, emp_no, salary from (select dept_no,d.emp_no,salary, rank()over(partition by dept_no order by salary desc) s from dept_emp d join salaries s on d.emp_no = s.emp_no) t1 where t1.s = 1 order by dept_no