I want you to filter the rows between a date range but I only want you to return the rows of a time range of each of the days included in the previous date range.

For example, you would like to filter out all the rows between March 1 and March 3, 2020 and also only those between 14:00 and 18:00.

So far I can filter between two dates or between two hours but it doesn't work when I put the two things together. I don't get any records.

and BEGIN_INTERVAL_TIME BETWEEN to_date('19/04/2020', 'DD/MM/YYYY') AND to_date('20/04/2020','DD/MM/YYYY')
and BEGIN_INTERVAL_TIME BETWEEN to_date('15:00:00', 'HH24:MI:SS') AND to_date('16:00:00','HH24:MI:SS')


SQL> select snap_id, begin_interval_time, end_interval_time from dba_hist_snapshot
     where begin_interval_time between date'2020-04-19' and date'2020-04-22'
     and begin_interval_time between trunc(begin_interval_time, 'DD') + 14/24 and trunc(begin_interval_time, 'DD') + 18/24
     order by 1;

---------- ------------------------- -------------------------
        68 19-APR-20 PM 19-APR-20 PM
        69 19-APR-20 PM 19-APR-20 PM
        70 19-APR-20 PM 19-APR-20 PM
        71 19-APR-20 PM 19-APR-20 PM
        92 20-APR-20 PM 20-APR-20 PM
        93 20-APR-20 PM 20-APR-20 PM
        94 20-APR-20 PM 20-APR-20 PM
        95 20-APR-20 PM 20-APR-20 PM
       116 21-APR-20 PM 21-APR-20 PM
       117 21-APR-20 PM 21-APR-20 PM
       118 21-APR-20 PM 21-APR-20 PM
       119 21-APR-20 PM 21-APR-20 PM

12 rows selected.
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.