I am running a query on a monthly basis to select data on the basis of months JAN,FEB,MAR,APR,SEP OCT,NOV,DEC.
Lets say i am running this query in FEB 2018, then the data of JAN and FEB should come from current year(2018) and data from MAR,APR,SEP OCT,NOV,DEC should come from previous year(2017). How do i handle this with SYSDATE.
>SELECT * FROM MY_TABLE WHERE MONTH_NAME
IN ('JAN','FEB','MAR','APR','SEP','OCT','NOV','DEC')
AND
YEAR=TO_CHAR(TRUNC(SYSDATE),'YYYY');
Assuming i have columns MONTH_NAME having all month names and YEAR with year to match the record.