SELECT DISTINCT A.GP_PAYGROUP , A.CAL_ID FROM PS_GP_CAL_RUN_DTL A , PS_GP_CAL_RUN_DTL B WHERE A.GP_PAYGROUP = B.GP_PAYGROUP AND A.COUNTRY = B.COUNTRY AND A.CALC_TYPE = B.CALC_TYPE AND A.CALC_TYPE = 'A' AND A.CAL_FINAL_TS <= ( SELECT MAX(C.CAL_FINAL_TS) FROM PS_GP_CAL_RUN_DTL C , PS_GP_CAL_RUN D WHERE (C.CAL_FINAL_TS < B.CAL_FINAL_TS AND B.CAL_RUN_ID = D.CAL_RUN_ID AND C.GP_PAYGROUP = B.GP_PAYGROUP AND C.COUNTRY = B.COUNTRY AND C.CALC_TYPE = B.CALC_TYPE AND D.RUN_FINALIZED_IND = 'Y') OR (C.CAL_FINAL_TS < B.CAL_IDNT_TS AND B.CAL_RUN_ID = D.CAL_RUN_ID AND C.GP_PAYGROUP = B.GP_PAYGROUP AND C.COUNTRY = B.COUNTRY AND C.CALC_TYPE = B.CALC_TYPE AND D.RUN_FINALIZED_IND = 'N'))
|