I have table that stores comma separated strings - I've created a solution via PHP that can separate the array and display the data as required; however, I now have the need to do this strictly by SQL query.
So here is what I start with: ID | TIME | CODES
1 | '2','','','8','','','2','','','2','','','4','','','3','','' | '102','104','105','106','107','108'
2 | '4','','','4','','','8','','','2','','','2','','' | '105','106','107','114','401'
every 3 values in the time belong to the code. So I need to combine everything into a single table to run some sums by category.
Something along the lines of this for an output:
ID | RT | PT | OT | CODE
---------------------------------
1 | 2 | NULL | NULL | 102
1 | 8 | NULL | NULL | 104
1 | 2 | NULL | NULL | 105
1 | 2 | NULL | NULL | 106
1 | 4 | NULL | NULL | 107
1 | 3 | NULL | NULL | 108
2 | 4 | NULL | NULL | 105
2 | 4 | NULL | NULL | 106
2 | 8 | NULL | NULL | 107
2 | 2 | NULL | NULL | 114
2 | 2 | NULL | NULL | 401
NULL, blank or 0 will work where nothing was provided ('')