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

后端 未结 5 2275
醉话见心
醉话见心 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:24

    I would tend to suspect that Tony is correct and that you really only want to TRUNC the right-hand side of the expression.

    If you do want to TRUNC both sides of the expression and you're encountering performance issues, you probably need a function based index

    CREATE INDEX idx_problem_trunc_dt_occured
        ON problem( trunc( date_occurred ) );
    

    That would allow your original query to use the function-based index.

提交回复
热议问题