By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
| Rownum | id_suboperation | id_element |
|---|---|---|
| 1 | 1 | 1 |
| 2 | 2 | 2 |
| 3 | 3 | 3 |
| 4 | 4 | 1 |
| 5 | 4 | 2 |
| 6 | 5 | 1 |
| 7 | 5 | 3 |
| @sql |
|---|
| SELECT (@rownum := @rownum+1) AS Rownum, id_suboperation, id_element FROM (SELECT * FROM (SELECT id AS id_suboperation, REVERSE(REVERSE(SUBSTRING_INDEX( SUBSTRING_INDEX(subOperation,',',1),',',-1))+0) AS id_element FROM mytable union all SELECT id AS id_suboperation, REVERSE(REVERSE(SUBSTRING_INDEX( SUBSTRING_INDEX(subOperation,',',2),',',-1))+0) AS id_element FROM mytable union all SELECT id AS id_suboperation, REVERSE(REVERSE(SUBSTRING_INDEX( SUBSTRING_INDEX(subOperation,',',3),',',-1))+0) AS id_element FROM mytable union all SELECT id AS id_suboperation, REVERSE(REVERSE(SUBSTRING_INDEX( SUBSTRING_INDEX(subOperation,',',4),',',-1))+0) AS id_element FROM mytable ) sq GROUP BY id_suboperation, id_element) vr CROSS JOIN (SELECT @rownum := 0) rn ORDER BY id_suboperation, id_element; |
| Rownum | id_suboperation | id_element |
|---|---|---|
| 1 | 1 | 1 |
| 2 | 2 | 2 |
| 3 | 3 | 3 |
| 4 | 4 | 1 |
| 5 | 4 | 2 |
| 6 | 5 | 1 |
| 7 | 5 | 3 |
| 8 | 6 | 2 |
| 9 | 6 | 4 |
| 10 | 6 | 5 |
| 11 | 7 | 3 |
| 12 | 7 | 53 |
| 13 | 8 | 3 |