The following is a direct simplification of the query in question, taking MAX (any row) versus MIN (any row). Scrum Meister's answer also corrects the OP logic to properly serve spaces between jobs.
That should be all you need. Having a student_schools JOINed table does not seem to add value unless there are cases where position_rd records exist without
student_schools .
CREATE TABLE student_totalexp2 nologging compress AS SELECT b.member_sk, NVL(MAX(TO_DATE(b.end_date,'yyyymm')), SYSDATE) - MIN(TO_DATE(b.start_date,'yyyymm')) as days_experience FROM rdorwart.position_rd b GROUP BY b.member_sk HAVING NVL(MAX(TO_DATE(b.end_date,'yyyymm')), SYSDATE) - MIN(TO_DATE(b.start_date,'yyyymm')) < 730
- NVL will take care of replacing nonexistent end_date with SYSDATE
If you need to check student_schools , just add an INNER JOIN to it. Nowhere else is needed.
source share