Query : Finding Subordinates and their subordinates

SELECT per.EMPLOYEE_NUMBER,per.FULL_NAME
FROM hr.per_all_people_f per
,hr.per_person_type_usages_f usg
,hr.per_person_types ppt
,hr.per_all_assignments_f paf
WHERE per.person_id = paf.person_id
AND paf.primary_flag = 'Y'
AND per.person_id = usg.person_id
AND usg.person_type_id = ppt.person_type_id
AND ppt.user_person_type = 'Employee'
AND TRUNC(SYSDATE) BETWEEN per.effective_start_date AND per.effective_end_date
AND TRUNC(SYSDATE) BETWEEN paf.effective_start_date AND paf.effective_end_date
AND TRUNC(SYSDATE) BETWEEN usg.effective_start_date AND usg.effective_end_date
AND ( per.person_id IN
(SELECT v.person_id FROM (SELECT person_id, supervisor_id
FROM hr.per_all_assignments_f s
WHERE TRUNC(SYSDATE) BETWEEN s.effective_start_date AND s.effective_end_date
AND s.primary_flag = 'Y'
AND s.assignment_type = 'E') v
CONNECT BY v.supervisor_id = PRIOR v.person_id
START WITH v.person_id = )
or PAF.PERSON_ID = )

0 comments:

Post a Comment