我使用开窗通过了,详解如下:

1、开窗排名
首先使用开窗将薪水进行排名

select 
      d.dept_no,
      d.emp_no,
      s.salary,
      row_number() over(partition by d.dept_no order by s.salary desc) as ranking
    from
      dept_emp as d
    join
      salaries as s
    on d.emp_no = s.emp_no

2、根据排名筛选
从1获得的表格中,根据where条件ranking=1选出最高薪水(当然如果存在同一员工相同薪水的情况,使用dense_rank开窗亦可),最终完整代码如下:

select
  dept_no,
  emp_no,
  salary
from (
    select 
      d.dept_no,
      d.emp_no,
      s.salary,
      row_number() over(partition by d.dept_no order by s.salary desc) as ranking
    from
      dept_emp as d
    join
      salaries as s
    on d.emp_no = s.emp_no ) as t
where 
  ranking = 1
order by
  dept_no