“ORA-00904:”RN“:无效标识符00904

时间:2017-04-18 12:57:42

标签: sql oracle

我正在尝试编写查询以获取有关在每个部门中首先雇佣的员工的信息。我正在写下面的查询,我得到了

  

“ORA-00904:”RN“:标识符无效   00904. 00000 - “%s:无效标识符”

查询:

select employee_id, department_id, first_name, last_name, hire_date, 
       ROW_NUMBER () over (partition by department_id order by hire_date) as rn
from employees
where rn =1;

您能告诉我“rn”标识符有什么问题吗?

1 个答案:

答案 0 :(得分:2)

您需要使用子查询或CTE:

select e.*
from (select employee_id, department_id, first_name, last_name, hire_date, 
             ROW_NUMBER () over (partition by department_id order by hire_date) as rn
      from employees e
     ) e
where rn = 1;