我正在尝试获得每个部门的最高3个最高薪水,但是在我的代码q.salary的末尾我收到以下错误:ORA-00904:“Q”。“SALARY”:无效的标识符
这是我的代码
with query as (
select max(salary), department_id
from employees
group by department_id
)
SELECT ROWNUM as RANK,
e.last_name,
e.salary
FROM (
select department_id, salary
from employees e,
query q
where e.salary = q.salary
)
where rownums <=3
提前谢谢
答案 0 :(得分:1)
您需要为列表达式max(salary)...
添加别名select max(salary) max_salary ...
...然后随后将其称为max_salary。
“rownums”也应该是“rownum”。
答案 1 :(得分:1)
您需要为聚合命名:
select max(salary) as salary,
department_id
from employees group by department_id