user4196435
user4196435

Reputation:

How do I return all data for the previous month in SQL?

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

Answers (1)

Jeffrey Kemp
Jeffrey Kemp

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

Related Questions