SELECT A.EMPLID , A.EMPL_RCD , B.EFFDT , B.ESTABID , B.POSTAL , C.TRANSPORT_RT FROM PS_JOB A , PS_ESTAB_TBL B , PS_ESTAB_TBL_FRA C WHERE A.ESTABID = B.ESTABID AND C.ESTABID = B.ESTABID AND C.EFFDT = B.EFFDT AND ( B.EFFDT = ( SELECT MAX(D.EFFDT) FROM PS_ESTAB_TBL D WHERE A.ESTABID = D.ESTABID AND D.EFFDT <= A.EFFDT AND D.EFF_STATUS = 'A' ) OR ( B.EFFDT > A.EFFDT AND (B.EFFDT < ( SELECT MIN(E.EFFDT) FROM PS_JOB E WHERE E.EMPLID = A.EMPLID AND E.EMPL_RCD = A.EMPL_RCD AND E.EFFDT > A.EFFDT) OR NOT EXISTS ( SELECT 'X' FROM PS_JOB E WHERE E.EMPLID = A.EMPLID AND E.EMPL_RCD = A.EMPL_RCD AND E.EFFDT > A.EFFDT) ) ) ) AND B.EFF_STATUS = 'A'
|