When you use a timestamp
column with string literals like that, the timestamp
is implicitly cast to varchar
, and the comparison is performed lexicographically - which, of course, is not the behavior you want.
You can use the to_timestamp
to explicitly force the cast in the direction you want:
SELECT COUNT(ORDER_ID)
FROM atable
WHERE order_type = 'INCOMPLETE' AND
"DATE" BETWEEN TO_TIMESTAMP('31-OCT-14', 'DD-MON-YY') AND
TO_TIMESTAMP('07-NOV-14', 'DD-MON-YY')
EDIT:
According to the clarification in the comments, you need a group by
clause to the results per day:
SELECT TO_TIMESTAMP("DATE", 'DD-MON-YY'), COUNT(ORDER_ID)
FROM atable
WHERE order_type = 'INCOMPLETE' AND
"DATE" BETWEEN TO_TIMESTAMP('31-OCT-14', 'DD-MON-YY') AND
TO_TIMESTAMP('07-NOV-14', 'DD-MON-YY')
GROUP BY TO_TIMESTAMP("DATE", 'DD-MON-YY')