【发布时间】:2021-08-07 17:51:24
【问题描述】:
我需要从 Oracle HR Schema 中选择城市、城市的最高薪水和薪水最高的员工姓名。 我尝试执行以下代码,但城市名称重复:
select l.city, e.last_name, e.salary from locations l
inner join departments d on l.location_id = d.location_id
inner join employees e on d.department_id = e.department_id
and e.salary = (select max(salary) from employees where department_id = d.department_id)
group by l.city, e.last_name, e.salary
order by e.salary;
我的代码有什么问题? 我已经附上了我需要的结果。Correct SQL result
【问题讨论】:
标签: oracle greatest-n-per-group