I have this kind of data on a Oracle SQL DB:
personId lastEvent currentEvent nextEvent
1 null 1 2
1 1 2 3
1 2 3 4
1 3 4 null
For a single row like
personId lastEvent currentEvent nextEvent
1 null 1 2
I want to extract the two rows extracted by combining together the events columns and categorizing these two rows to the specific currentEvent. For example:
Row #1
personId lastEvent currentEvent nextEvent
1 null 1 2
Result #1
personId event1 event2 currentEvent
1 null 1 1
1 1 2 1
Row #2
personId lastEvent currentEvent nextEvent
1 1 2 3
Result #2
personId event1 event2 currentEvent
1 1 2 2
1 2 3 2
etc..... I know the existence of the clause CONNECT BY but I'm not really able to figure out the query to obtain these results.