where子句,case语句

时间:2019-06-13 14:38:28

标签: sql oracle

我需要将以下所示的case语句添加到主查询中,以便在不同日期时排除成员。如何添加它?谢谢。

    SELECT DISTINCT
    PI.INDEX_VALUE, 
    LB.STATE,
    UNIQUE_ID, 
    'AL',
    'EN',
    MBP.START_DATE,
   ADD_MONTHS(MBP.START_DATE,12)
   FROM dwteam.PATIENT_DETAILS        PD 
   INNER JOIN dwteam.ADMIN_CLIENT        AC 
     ON AC.CLIENT_ID = PD.CLIENT_ID
        and AC.DELETED_BY is null
      --   and AC.IS_ACTIVE =1  
    INNER JOIN dwteam.MEM_BENF_PROG MBP
      ON MBP.MEMBER_ID = PD.PATIENT_ID
      and MBP.DELETED_BY is null
    INNER JOIN dwteam.BENF_PLAN_PROG BPP
       ON BPP.BEN_PLAN_PROG_ID = MBP.BEN_PLAN_PROG_ID
    INNER JOIN dwteam.BENEFIT_PROGRAM BPR
      ON BPR.BENEFIT_PROGRAM_ID = BPP.BENEFIT_PROGRAM_ID
      and BPR.DELETED_BY is null
    left JOIN dwteam.PATIENT_INDEX PI
      ON PI.PATIENT_ID=MBP.MEMBER_ID
      AND PI.INDEX_ID in (10073,10071)
    left join UHG_000613129.HFS_LOB_ID_XWALK LB
      on trim(upper(replace(replace(AC.CLIENT_NAME,'C&S',''),'M&R','')))=trim(upper(STATE_DESC))
    WHERE PROGRAM_NAME IN ('Healthy Pregnancy','High Risk Pregnancy')
        AND (sysdate  <  ADD_MONTHS(MBP.START_DATE,12)
        OR sysdate  <  ADD_MONTHS(MBP.END_DATE,12))





    CASE WHEN MBP.CLOSURE_ID = 40 THEN MBP.END_DATE - 120
         WHEN MBP.CLOSURE_ID IN (5,18,103) THEN MBP.END_DATE - 365
         ELSE MBP.END_DATE - 270 END AS END_DATE

1 个答案:

答案 0 :(得分:0)

您可以使用CTE命名表达式,然后将其用于外部查询中的任何目的。

我不知道您查询的所有详细信息,但应采用以下格式:

path2

根据需要进行调整。