窗口函数一步到位
select dept_no,emp_no,salary maxSalary
from
(SELECT *,rank()over(PARTITION by dept_no order by salary desc) r
from dept_emp d join salaries s on d.emp_no=s.emp_no
) a
where a.r=1
先建个包含所有信息且分好组排好序的子表,然后从子表里把序号第一的所需信息提取出来 话说同样代码放mysql里就报错,不知哪里出了问题