SELECT SETID , RESOURCE_SUB_CAT , EFFDT AS EFF_ST_DT , CASE WHEN LEAD(CONCAT(SETID ,RESOURCE_SUB_CAT) ,1 ,NULL) OVER ( ORDER BY SETID ,RESOURCE_SUB_CAT ,EFFDT) <> CONCAT (SETID ,RESOURCE_SUB_CAT) THEN TO_DATE('9999-12-31' , 'YYYY-MM-DD') ELSE CASE WHEN LEAD(EFFDT ,1 ,NULL) OVER ( ORDER BY SETID ,RESOURCE_SUB_CAT ,EFFDT) = EFFDT THEN EFFDT ELSE LEAD(EFFDT-1 ,1 ,TO_DATE('9999-12-31' , 'YYYY-MM-DD')) OVER ( ORDER BY SETID ,RESOURCE_SUB_CAT ,EFFDT) END END AS EFF_END_DT FROM PS_PROJ_SUBCAT_TBL ORDER BY 1 , 2 , 3
|