How to compare two DATE values based only on date part in Oracle?

后端 未结 5 2281
醉话见心
醉话见心 2021-02-19 18:53

I am trying to get counts for last 30 days with the following query -

SELECT date_occured, COUNT(*) FROM problem
WHERE date_occured >= (CURRENT_DATE - 30)
GRO         


        
5条回答
  •  名媛妹妹
    2021-02-19 19:38

    Here is the index friendly approach.

    you don't need to use functions on columns if you use Oracle's Native MONTHS_BETWEEN function.

    It returns difference in number of months. Days are also given as difference but on the precision side that is why I preferred to use BETWEEN clause

    WHERE MONTHS_BETWEEN(date_occured, CURRENT_DATE - 30) BETWEEN 0 AND 1
    

提交回复
热议问题