Oracle date function for the previous month

后端 未结 6 2108
醉梦人生
醉梦人生 2021-02-18 17:25

I have the query below where the date is hard-coded. My objective is to remove the harcoded date; the query should pull the data for the previous month when it runs.

<         


        
6条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-18 17:59

    I believe this would also work:

    select count(distinct switch_id)   
      from xx_new.xx_cti_call_details@appsread.prd.com  
     where 
       dealer_name =  'XXXX'    
       and (creation_date BETWEEN add_months(trunc(sysdate,'mm'),-1) and  trunc(sysdate, 'mm'))
    

    It has the advantage of using BETWEEN which is the way the OP used his date selection criteria.

提交回复
热议问题