SELECT
*
FROM
(SELECT emp_id,
MAX (CASE WHEN visit_number = (SELECT visit_number
FROM (SELECT visit_number, rownum srl
FROM (SELECT visit_number
FROM emps p1,
depts s,
edu_emp_visit_types_xref x
WHERE p1.emp_id = p.emp_id
AND p1.dept_id = s.dept_id
AND x.edu_id = 1
AND x.country = s.country
AND x.emp_visit_type_name = 'Enrolled'
ORDER BY visit_order))
WHERE srl = 1) THEN visit_date END ) visit1
FROM emp_VISITS
WHERE edu_id = 1
GROUP BY emp_id) tl,
empS p,
deptS s
WHERE p.emp_id = edc.emp_id
AND p.emp_id = tl.emp_id
AND s.dept_id = p.dept_id
|