Reputation: 69
Is there a way by which I can simplify the below using BETWEEN
?
select *
from support
where
(datereceived <= sysdate) and (datereceived >= add_months (sysdate,-3));
Many thanks
Upvotes: 0
Views: 34
Reputation: 1269603
Given that datereceived
probably refers only to something that has already happened, I don't think you need to check that there is no future date.
So, a simpler comparison would be:
where datereceived >= add_months(sysdate, -3)
Then, you might not realize that sysdate
has a time component. And you probably don't care about specific times. So, you might actually intend:
where datereceived >= add_months(trunc(sysdate), -3)
Upvotes: 1
Reputation: 13509
You can write -
SELECT *
FROM support
WHERE datereceived BETWEEN ADD_MONTHS(SYSDATE, -3) AND SYSDATE;
Upvotes: 1