SELECT a.supervisor_id , a.supervis_empl_rcd , a.emplid , a.empl_rcd , a.reports_to , COUNT(DISTINCT a1.emplid %Concat %Cast(a1.empl_rcd,number, character) ) FROM ps_hr_direct_rep_4 a , ps_hr_direct_rep_4 a1 , PS_JOB B , PS_JOB C WHERE a.drill_down_flag = 'Y' AND a.supervisor_flag = 'Y' AND a1.drill_down_flag = 'Y' AND a.emplid = A1.supervisor_id AND a.empl_rcd = A1.supervis_empl_rcd AND C.PER_ORG = 'EMP' AND A.EMPLID = C.EMPLID AND A.EMPL_RCD = C.EMPL_RCD AND A.JOB_EFFDT = C.EFFDT AND C.EFFSEQ = ( SELECT MAX(EFFSEQ) FROM PS_JOB JBC WHERE JBC.EMPLID = C.EMPLID AND JBC.EFFDT = C.EFFDT AND JBC.EMPL_RCD = C.EMPL_RCD) AND B.PER_ORG = 'EMP' AND A1.EMPLID = B.EMPLID AND A1.EMPL_RCD = B.EMPL_RCD AND A1.JOB_EFFDT = B.EFFDT AND B.EFFSEQ = ( SELECT MAX(JB2.EFFSEQ) FROM PS_JOB JB2 WHERE JB2.EMPLID = B.EMPLID AND JB2.EFFDT = B.EFFDT AND JB2.EMPL_RCD = B.EMPL_RCD) GROUP BY a.supervisor_id , a.supervis_empl_rcd , a.emplid , a.empl_rcd , a.reports_to
|