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());
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.