How to get data for current month, previous month and same month(current month) previous year?

Database
Fan

How to get data for current month, previous month and same month(current month) previous year?

I have to get data for an incured date which should have current month, previous month and same month(current month) previous year? 

I need to get data for these three months for comparison.

Example : 2017-12-01, 2017-11-01 and 2016-12-01

Any idea or help will be really appreciated.

Thank you

3 REPLIES
Junior Contributor

Re: How to get data for current month, previous month and same month(current month) previous year?

A combination of ADD_MONTHS plus TRUNC/LAST_DAY...

Fan

Re: How to get data for current month, previous month and same month(current month) previous year?

Sorry! could you please elaborate? Thank you.

Highlighted
Teradata Employee

Re: How to get data for current month, previous month and same month(current month) previous year?

See the SQL Functions manual at info.teradata.com for your release of Teradata.

select trunc(date'2017-12-22','RM') (format'y4-mm-dd')
    ,add_months(trunc(date'2017-12-22','RM'),-1)
    ,add_months(trunc(date'2017-12-22','RM'),-12);