Skip to content
Advertisement

How to display multiple rows based row difference data In SQL?

I have a table as follows:

I want to split this data based on above data.

If FromYm(Means yearmonth) and ToYM(Means yearmonth) difference is two then result as two rows:

Example result :

Tried Code

Advertisement

Answer

You can do it using recursive cte:

You can test on this db<>fiddle

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