SELECT DISTINCT
A.STRM,
'2021' IPEDS_YEAR,
A.INSTITUTION,
A.UM_INST_HOST,
A.EMPLID,
A.ACAD_PROG_PRIMARY,
A.UM_DEGREE_NONDEG,
A.UM_ETHNIC_GRP_DESC,
A.Acad_Level_Bot,
A.Um_Unt_Tak_Prg_Rc,
A.SEX,
A.ACAD_CAREER,
B.STDNT_ENRL_STATUS,
B.CRSE_CAREER,
A.ADMIT_TERM,
A.ADMIT_TYPE,
A.RESIDENCY,
A.ACAD_PROG,
A.ACAD_PLAN,
A.UM_ACAD_PLAN_DESCR,
A.CITY,
A.STATE,
A.STATE_DESCR1,
A.POSTAL,
A.COUNTRY,
A.COUNTRY_DESCR1,
B.SUBJECT,
B.CATALOG_NBR,
B.CLASS_SECTION,
B.CLASS_NBR,
B.DESCR,
B.ACAD_ORG,
B.UM_ACAD_ORG_DESCR,
B.UNT_PRGRSS,
B.UNT_PRGRSS_FA,
B.CAMPUS,
B.LOCATION,
B.DESCR_LOCATION,
B.um_class_dlv_mode,
B.um_dist_class,
B.UM_DIST_ATTR_FLAG,
B.INSTRUCTION_MODE,
E.START_DT,
F.Um_Cohort_Type,
A.Degree,
CASE
WHEN F.Um_Cohort_Type in ('FYR', 'EFY') then 'First-time'
WHEN F.Um_Cohort_Type = 'TRF' then 'Transfer-in'
else 'Continuing'
end as cohort_category,
'CS_IPEDS_MT' DI_Job_Pid,
sysdate DI_Create_Date,
sysdate DI_Modified_Date
FROM SYSADM.PS_UM_STUD_CENS_VW A
LEFT OUTER JOIN SYSADM.PS_UM_STD_ENR_C_VW B
ON A.EMPLID = B.EMPLID
AND A.INSTITUTION = B.INSTITUTION
AND A.STRM = B.STRM
LEFT OUTER JOIN SYSADM.PS_CLASS_TBL E
ON B.INSTITUTION = E.INSTITUTION
AND B.STRM = E.STRM
AND B.CLASS_NBR = E.CLASS_NBR
LEFT OUTER JOIN SYSADM.PS_um_stdnt_cohort F
on A.INSTITUTION = F.INSTITUTION
and A.ACAD_CAREER = F.ACAD_CAREER
and A.emplid = F.EMPLID
and A.strm = F.Um_Cohort_Strm
and F.um_cohort_code='RETENTION'
and ((F.action_dt = (SELECT MAX(F_ED.action_dt)
FROM sysadm.ps_um_stdnt_cohort F_ED
WHERE F.INSTITUTION = F_ED.INSTITUTION
and F.ACAD_CAREER = F_ED.ACAD_CAREER
and F.EMPLID = F_ED.EMPLID
and F.UM_COHORT_STRM = F_ED.UM_COHORT_STRM
and F.um_cohort_code = F_ED.um_cohort_code
and F_ED.action_dt <= SYSDATE)) or F.action_dt is null)
WHERE A.STRM BETWEEN '2030' AND '2130'
AND E.START_DT BETWEEN TO_DATE('20' || substr('2030', 1, 2) || '-07-01','YYYY-MM-DD') AND TO_DATE('20' || substr('2130', 1, 2) || '-06-30','YYYY-MM-DD')