SELECT RSLT.EMPLID ,RSLT.CAL_RUN_ID ,RSLT.EMPL_RCD ,RSLT.GP_PAYGROUP ,RSLT.RSLT_SEG_NUM ,RSLT.USER_KEY1 ,RSLT.USER_KEY2 C ,C.PIN_NM ,SUM(ACUM.CALC_VAL-RSLT.GPGB_ER_NIC_VALUE) FROM PS_GPGB_RTI_RSLT RSLT , PS_GP_RSLT_ACUM ACUM , PS_GP_PIN C WHERE RSLT.GPGB_ER_NIC_VALUE <> 0 AND RSLT.EMPLID = ACUM.EMPLID AND RSLT.EMPL_RCD = ACUM.EMPL_RCD AND RSLT.GP_PAYGROUP = ACUM.GP_PAYGROUP AND RSLT.CAL_ID = ACUM.CAL_ID AND ACUM.PIN_NUM = C.PIN_NUM AND RSLT.CAL_RUN_ID = ACUM.CAL_RUN_ID AND RSLT.EMPL_RCD = ACUM.EMPL_RCD AND RSLT.GP_PAYGROUP = ACUM.GP_PAYGROUP AND RSLT.CAL_ID = ACUM.CAL_ID AND RSLT.ORIG_CAL_RUN_ID = ACUM.ORIG_CAL_RUN_ID AND RSLT.RSLT_SEG_NUM = ACUM.RSLT_SEG_NUM AND ACUM.SEQ_NUM8 = ( SELECT MAX(ACUM1.SEQ_NUM8) FROM PS_GP_RSLT_ACUM ACUM1 WHERE ACUM1.EMPLID = ACUM.EMPLID AND ACUM1.CAL_RUN_ID = ACUM.CAL_RUN_ID AND ACUM1.EMPL_RCD = ACUM.EMPL_RCD AND ACUM1.GP_PAYGROUP = ACUM.GP_PAYGROUP AND ACUM1.CAL_ID = ACUM.CAL_ID AND ACUM1.ORIG_CAL_RUN_ID = ACUM.ORIG_CAL_RUN_ID AND ACUM1.RSLT_SEG_NUM = ACUM.RSLT_SEG_NUM AND ACUM1.PIN_NUM = ACUM.PIN_NUM) GROUP BY RSLT.EMPLID, RSLT.CAL_RUN_ID, RSLT.EMPL_RCD, RSLT.GP_PAYGROUP, RSLT.RSLT_SEG_NUM, RSLT.USER_KEY1 ,RSLT.USER_KEY2, C.PIN_NM
|