This is a common question, but I found my problem to be unique. I have a database in MySQL workbench that has multiple order number (inconsistent length) and status conditions (three types) in a single column. I must separate the order numbers from their status and the order numbers from each other.
What I have:
|NUMBER_STATUS|
|1234-START, 12323-END|
|234 - END, 12423-START, 53443-WIP|
What my final output should be:
|Number_STATUS_1| |Number_STATUS_2| |Number_STATUS_3|
1234 12323
234 12423 53443
There are over 25,000 data points. So far, I have tried writing a left function:
SELECT *,
LEFT(NUMBER_STATUS, locate('-START', NUMBER_STATUS)-1) AS 'NUMBER_STATUS_1'
FROM Request;
This function does exactly what I want: Creates a new column with the status removed, but does not carry over any other data in its row.
I thought of three plans to attack this:
create new columns split the original by pieces. I can do this in excel using "split text into cells" and then bring it into MySQL Workbench, but I know SQL is more powerful, so I would like to write a script for this.
Create a pseudo table that stores each new column (Number status 1, number status 2, etc) but the data changes daily so I don't want to limit the number of new columns that can be created.
Ask you all.
Some other links I referenced for help:
Split one column to multiple columns but data will vary SQL
Split string and return data in multiple columns
But my knowledge of SQL is still growing and I have no idea what these functions mean, I would greatly appreciate the help.