Skip to content
Advertisement

SQL concat case select when trying to add new column of previous month data

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.

as monthyear from table

Advertisement

Answer

You need 2 CASE statements inside concat(), for the month and the year:

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement