我是peoplesoft的新手。我可以在概念上理解生效日期,但我仍然在 SQR 中苦苦挣扎。如何从 PS_JOB 表中检索有效日期的 empid?如何从 ps_names 中为检索到的 empid 检索有效的 empname?提前致谢!
3 回答
加入姓名和工作表及其各自的生效日期。假设您只需要在职员工的姓名,我在这里采用了 A、L、P、S 员工。如果没有,您可以删除 empl_status 标准。您还需要在 main 条件中指定 name_type ,否则可能会为一个 empid 返回多行。
SELECT * FROM PS_NAMES N, PS_JOB J
WHERE N.EMPLID = J.EMPLID
AND N.EFFDT = (SELECT MAX(N1.EFFDT) FROM PS_NAMES N1
WHERE N1.EMPLID= N.EMPLID
AND N1.NAME_TYPE = N.NAME_TYPE
AND N1.EFFDT <= SYSDATE)
AND J.EFFDT = (SELECT MAX(J1.EFFDT) FROM PS_JOB J1
WHERE J1.EMPLID = J.EMPLID
AND J1.EMPL_RCD = J.EMPL_RCD
AND J1.EFFDT <= SYSDATE)
AND J.EFFSEQ = (SELECT MAX(J2.EFFSEQ) FROM PS_JOB J2
WHERE J2.EMPLID = J.EMPLID
AND J2.EMPL_RCD = J.EMPL_RCD
AND J2.EFFDT = J.EFFDT)
AND J.EMPL_STATUS IN ('A','L','P','S')
当前名称 - 从 ps_names_vw 视图中,您可以对 ps_job 表使用类似的 where 子句。
select a.emplid,
a.name_type,
a.effdt,
a.last_name,
a.first_name,
a.middle_name,
a.name_prefix,
a.name_suffix,
a.last_name_srch,
a.first_name_srch,
a.name_display
from ps_names a
where a.effdt = (select max (b.effdt)
from ps_names b
where b.emplid = a.emplid and
b.name_type = a.name_type and
b.effdt <= to_date (to_char (sysdate, 'YYYY-MM-DD'), 'YYYY-MM-DD'));
下面的查询将从 PS_JOB 获取具有 Emplid 'XXX' 的员工的最新数据
SELECT * FROM PS_JOB J WHERE J.EMPLID = 'XXX' AND J.EFFDT = (SELECT MAX(J1.EFFDT) FROM PS_JOB J1 WHERE J1.EMPLID =J.EMPLID AND J1.EMPL_RCD = J.EMPL_RCD AND J1.EFFDT < TRUNC(SYSDATE)) AND J.EMPL_RCD = ( SELECT MAX(J2.EMPL_RCD) 从 PS_JOB J2 WHERE J2.EMPLID = J.EMPLID AND J2.EFFDT = J.EFFDT ) AND J.EFFSEQ = ( SELECT MAX(J3.EFFSEQ) ) 从 PS_JOB J3 WHERE J3.EMPLID = J.EMPLID AND J3.EMPL_RCD = J.EMPL_RCD AND J3.EFFDT = J.EFFDT)
按 J.EMPLID、J.EMPL_RCD、J.EFFDT、J.EFFSEQ 排序