How to exclude certain hours and certain days in a date range in oracle sql
This is the table schema that i have:
CREATE TABLE TEST
(
COL1 NUMBER NOT NULL,
START_TIME DATE NOT NULL,
DURATION NUMBER,
COL2 NUMBER,
CONSTRAINT PK_TEST PRIMARY KEY
(
COL1,
START_TIME
)
This is the query i have to select all the rows within a time range:
SELECT
f.col2,
TRUNC(f.START_TIME,'DD'),
FROM test f
WHERE
(f.START_TIME >= TIMESTAMP '2007-04-13 00:00:00' AND f.START_TIME < TIMESTAMP '2007-07-20 00:00:00' )
GROUP BY
TRUNC(f.START_TIME,'DD')
If I want to exclude certain days, say Wednesday and Friday, how would the query be??
If I want to exclude certain hours, say the 3rd, 4th, 5th hour of the day and 23rd hour of the day(i.e, excluding 2am - 5am and 10pm - 11pm). Is it possible for me to provide just the list of hours i want to exclude, like [3,4,5,23] or do i need to give the range specifically?
Could you please tell me how the queries would be for the above cases. The hours and days to be excluded can vary, so the query shouldnt be specific for the numbers i have used.



