Say i have data like below
It need not be only four, it can be any number.
And i want the output in the following format
Thanks in advance...
You can do it either by using recursive view, or by looping in a procedure.