Reputation:
How do I return all data for the previous month in SQL. (NOT SQL SERVER). This is the code I have.
SELECT DOD
FROM ZZZ_DEPARTURE_DATES
WHERE DOD = (MONTH, -1, GETDATE());
Upvotes: 0
Views: 109
Reputation: 60312
For Oracle:
SELECT DOD
FROM ZZZ_DEPARTURE_DATES
WHERE DOD >= TRUNC(ADD_MONTHS(SYSDATE,-1),'MON')
AND DOD < TRUNC(SYSDATE,'MON');
Note: using this syntax is more likely to take advantage of an index on DOD
, if one exists.
Upvotes: 1