0

我希望每次都将结果限制在前 7 天,但是此查询总是抛出错误并且似乎没有按预期工作:

   SELECT 


   DD.DATE_DATE AS Rcv_Date,

    elig.PL_PREMIUMDESC,
    COUNT(DISTINCT(sERV.claim_nbr))  as Claim_Nbr


        from
        ft_service SERV

        inner join ft_claim claim 
        on SERV.claim_nbr=claim.claim_nbr 


         inner join  medical_cost_category mcc
         on SERV.medical_cost_category_dim_ck=mcc.medical_cost_category_dim_ck
    
         INNER JOIN DIM_DATE DD 
         ON DD.DATE_DIM_CK = CLAIM.RCVD_DATE_DIM_CK 
    

    
               left join member_elig_curr elig 
         on SERV.member_elig_curr_ck=elig.member_elig_curr_ck
    
          WHERE DD.DATE_DATE - ((DD.DATE_DATE -  CURRENT_DATE) MOD 7) ---GET ME PREVIOUS 7 DATS FOR 
         RCV DATE 
    
    

           AND elig.PL_CODE IN ('XXX', 'XXXA', 'XXXB') 
             AND SERV.CLAIM_NBR NOT LIKE '%XD%'
    
         GROUP BY 1, 2  
4

1 回答 1

0
DD.DATE_DATE BETWEEN  (current_date - INTERVAL '7' DAY) AND CURRENT_DATE

这就是问题的答案。在 where 子句中设置它将始终将数据限制为最近 7 天。

于 2020-11-17T00:46:27.033 回答