im solving the following task with analytic functions and i
m卡住了
task:编写一个查询,显示每个部门最近雇用的员工。如果是领带,则使用最低的员工ID。
select a.EMPLOYEE_ID,
a.DEPARTMENT_ID,
a.FIRST_NAME,
a.LAST_NAME,
a.HIRE_DATE,
a.JOB_ID
from (select ROW_NUMBER() over (PARTITION by department_id order by hire_date desc)
from hr.EMPLOYEES a) A
where A = 1 ;
您需要将要在外部查询中选择的列包含在内部查询的SELECT
子句中,并且需要为ROW_NUMBER
计算值提供别名:
select EMPLOYEE_ID,
DEPARTMENT_ID,
FIRST_NAME,
LAST_NAME,
HIRE_DATE,
JOB_ID
from (
select EMPLOYEE_ID,
DEPARTMENT_ID,
FIRST_NAME,
LAST_NAME,
HIRE_DATE,
JOB_ID,
ROW_NUMBER() over (PARTITION by department_id order by hire_date desc) AS rn
from hr.EMPLOYEES
)
where rn = 1 ;
你仍然需要回答问题的第二部分:
如果是领带,则使用最低的员工ID。
然而,由于这似乎是一个家庭作业问题,我将把它留给你来解决。