-1
我需要走出獲取轉移員工的行,這意味着之前的動作或動作「轉移」的前行中的具體行動。目前我正在通過effective_start_date條件來完成它。目前,這是我已經把代碼: -獲取之前像「轉移」
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)
但是這段代碼我沒有得到誰只有兩個排在他們的工作record-假設一個這些員工是出租,另一個轉移。對於那些僱員'僱用'行動將是轉出行。但兩者都是在同一天。只有有效的順序是不同的。對於這些員工,我需要添加有效的順序邏輯以及effective_start_date。我寫的代碼: -
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'
但是這也沒有給我相同的有效日期的行動爲轉移的員工。請幫助我。