John
John

Reputation: 437

Oracle SQL - Get records from current month last year

I'm working with Oracle SQL.

I'm trying to get all records from the current month and last year.

Example: This is August 12, so I want all records from 1-12 August 2017

The query gets me all records in the current month 2018.

BETWEEN trunc (sysdate, 'mm') AND SYSDATE

How to do the same for last year?

Upvotes: 1

Views: 942

Answers (2)

Ori Marko
Ori Marko

Reputation: 58892

You can use ADD_MONTHS function to get 12 months before:

Between trunc(ADD_MONTHS(sysdate,-12),'mm') and trunc(ADD_MONTHS(sysdate,-11),'mm')   

Upvotes: 2

Gordon Linoff
Gordon Linoff

Reputation: 1271111

You can do:

where date >= trunc(sysdate, 'mon') - interval '12' month and
      date < trunc(sysdate, 'mon') - interval '11' month

Upvotes: 2

Related Questions