-1

我试图获得每个部门的前 3 名最高薪水,但是在 q.salary 的代码末尾我收到以下错误:ORA-00904: "Q"."SALARY": invalid identifier

这是我的代码

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

先感谢您

4

2 回答 2

1

您需要别名列表达式 max(salary) ...

select max(salary) max_salary ...

...然后将其称为 max_salary 随后。

“rownums”也应该是“rownum”。

于 2013-05-12T11:40:39.903 回答
1

您需要为聚合命名:

select max(salary) as salary, 
       department_id 
from employees group by department_id
于 2013-05-12T11:40:49.643 回答