I have a data set in which I need to concat month and year for the previous month. the problem is it spans over two years. I need to create a statement in which mean the month – 1 = 0, month becomes 12 and year-1.
Select concat(case when month > 1 then select(month-1, year) when month = 1 then select(12, year -1) else select(month-1, year) end
as monthyear from table
You need 2 CASE statements inside concat(), for the month and the year:
select concat( case when month > 1 then month - 1 else 12 end, case when month > 1 then year else year - 1 end )