function - Splitting a cell in mySQL into multiple rows while keeping the same "ID" -
in table have 2 columns "sku" , "fitment". sku represents part , fitment represents vehicles part fit on. problem is, in fitment cells, there 20 vehicles in there, separated ^^. example
**sku -- fitment** part1 -- vehichle 1 information ^^ vehichle 2 information ^^ vehichle 3 etc
i looking split cells in fitment column, this:
**sku -- fitment** part1 -- vehicle 1 information part1 -- vehicle 2 information part1 -- vehicle 3 information
is possible do? , if so, mysql db able handle hundreds of thousands of items "splitting" this? imagine turn db of around 250k lines 20million lines. appreciated!
also little more background, going used drill down search function able match parts vehicles (year, make, model, etc) if have better solution, ears.
thanks
possible duplicate of this: split value 1 field two
unfortunately, mysql not feature split string function. in link above indicates there user-defined split function's.
a more verbose version fetch data can following:
select substring_index(substring_index(fitment, '^^', 1), '^^', -1) fitmentvehicle1, substring_index(substring_index(fitment, '^^', 2), '^^', -1) fitmentvehicle2 .... substring_index(substring_index(fitment, '^^', n), '^^', -1) fitmentvehiclen table_name;
- since requirement asks normalized format (i.e. not separated ^^) retrieved, better store in way in first place. , w.r.t db size bloat up, might want possibilities of archiving older data , deleting same table.
- also, should partition table using efficient partitioning strategy based on requirement. more easier archive , truncate partition of table itself, instead of row row.
Comments
Post a Comment