In that case you could use in the WHERE to:
1. Compare current month - 1 to date month
2. Compare the current year with the year of the date
This is easy using the function EXTRACT
:
The problem is in the case of month 1, which if subtracted would give 0 and the year should be subtracted as well. For this case, a simple logic using CASE WHEN
:
where (case when EXTRACT(month from sysdate) = 1
then 12
else EXTRACT(month from sysdate)-1 end) = EXTRACT(month from cliente.dtultcomp)
and (case when EXTRACT(month from sysdate) = 1
then EXTRACT(year from sysdate)-1
else EXTRACT(year from sysdate) end) = EXTRACT(year from cliente.dtultcomp)
With that, you’ll figure it out: "return the values of the whole previous month"
An example in SQL fiddle: http://sqlfiddle.com/#! 4/db477/1