I am written below code to get prev quarter and year ,
if current date is in 1st quarter , I have to get previous quarter (last year last quarter) , same time year has to be previous year.
if current quarter is 2 then previous quarter is 1 and year is current year ,
can we write below in simplified way ?
please help
SELECT
CASE WHEN TO_NUMBER(to_char(TO_DATE('04-01-2018','MM-DD-YYYY'),'Q')) -1=0
THEN extract(year from sysdate)-1 else extract(year from sysdate) end year ,
CASE WHEN TO_NUMBER(to_char(TO_DATE('04-01-2018','MM-DD-YYYY'),'Q')) -1= 0 then 4 else
TO_NUMBER(to_char(TO_DATE('04-01-2018','MM-DD-YYYY'),'Q')) -1 end last_qtr
FROM dual;