Most efficient way of getting all records within an 2 hour window

2448 views sql
-5

I would like to write a query that based on two date fields finds where there is a 2 hour or greater difference.

SELECT TO_DATE(Date_Fielda, 'DD-MON-YY HR24:MI:SS'), 
       TO_DATE(Date_Fieldb, 'DD_MON-YY, HR24:MI:SS')
FROM   DUAL;

how would I do this?

answered question

1 Answer

10

Well, you would select from a table and use a where clause. Here is a simple method in Oracle:

select t.*
from t
where abs(date_columna - date_columnb) > 2 / 24

If you know that one column comes earlier than the other, then:

select t.*
from t
where date_columna > date_columnb + interval '2 hour'

posted this

Have an answer?

JD

Please login first before posting an answer.