我需要获取员工的转出行,这意味着先前的操作或操作“转移”的前一行。目前我仅通过有效开始日期条件来完成它。目前这是我放的代码:-
SELECT PAAM.EFFECTIVE_START_DATE, PAAM.PERSON_ID,PAAM.ACTION_CODE FROM PER_ALL_ASSIGNMENTS_M PAAM
WHERE
TO_CHAR(PAAM.EFFECTIVE_START_DATE,'YYYY-MM-DD') =
(SELECT TO_CHAR(MAX(PAAM1.EFFECTIVE_START_DATE),'YYYY-MM-DD') FROM FUSION.PER_ALL_ASSIGNMENTS_M PAAM1
WHERE PAAM1.EFFECTIVE_START_DATE< (SELECT MAX(EFFECTIVE_START_DATE) FROM FUSION.PER_ALL_ASSIGNMENTS_M PAAM2 WHERE PAAM2.ACTION_CODE='TRANSFER'
AND PAAM2.PERSON_ID=PAAM1.PERSON_ID AND SYSDATE BETWEEN PAAM2.EFFECTIVE_START_DATE AND PAAM2.EFFECTIVE_END_DATE) AND PAAM1.PERSON_ID=PAAM.PERSON_ID)
但是通过这段代码,我没有得到那些工作记录中只有两行的员工——假设一个是 Hire,另一个是 Transfer。对于这些员工,“雇用”操作将是转出行。但两者是同一天。只有有效顺序不同。对于这些员工,我需要添加有效的序列逻辑以及有效的开始日期。我已经写了代码:-
select PAAM1.effective_start_date, paam1.effective_end_date, paam1.action_code, paam1.effective_sequence from PER_ALL_assignments_M PAAM,PER_ALL_ASSIGNMENTS_M PAAM1, per_all_people_f papf
where PAAM.person_id = paam1.person_id
and paam.person_id=papf.person_id
and paam.effective_start_date=(select max(paam3.effective_start_date)
from per_all_assignments_m paam3 where paam.person_id=paam3.person_id)
and paam.effective_sequence=
(select max (effective_sequence) from per_all_assignments_m paam4 where paam.person_id=paam4.person_id)
and paam1.effective_start_date = (SELECT MAX(paam5.EFFective_start_DaTe) from per_all_assignments_m paam5
where paam5.person_id = paam1.person_id and (paam5.effective_start_date < paam.effective_start_date
or (paam5.effective_start_date = paam.effective_start_date and paam1.effective_sequence < paam.effective_sequence )))
and paam1.effective_sequence =(SELECT MAX(paam6.effective_sequence) from per_all_assignments_m paam6
where paam6.person_id = paam1.person_id and paam6.effective_start_date = paam1.effective_start_date
and (paam1.effective_start_date<paam.effective_start_date or(paam1.effective_start_date=paam.effective_start_date and paam6.effective_sequence< paam.effective_sequence)))
and paam.action_code='TRANSFER'
但这也没有给我与转移相同的有效日期行动的员工。请帮帮我。