Good day, I have this table in green.

I want to regroup row 2 to 5 so the result should like row 11. Here is how row 2 to row 5 are connected:
Row 2 to Row 3: row 2 end_crct_id = row 3 crct_id,
Row 3 to Row 4: row 3 crct_id = row 4 begin_crct_id,
Row 4 to Row 5: row 4 end_crct_id = row 5 crct_id.
I have several of these cases, this only an example. The number of rows to combine varies every time.

