[英]Split column string into multiple columns strings
I have a entry in the table that is a string which is delimited by semicolons. 我在表中有一个条目,该条目是由分号分隔的字符串。 Is possible to split the string into separate columns?
可以将字符串分成单独的列吗? I've been looking online and at stackoverflow and I couldn't find one that would do the splitting into columns.
我一直在寻找联机状态和stackoverflow,但找不到一个可以拆分为各列的方法。
The entry in the table looks something like this (anything in brackets [] is not actually in my table. Just there to make things clearer): 表格中的条目看起来像这样(方括号[]中的任何内容实际上都不在我的表格中。只是为了使内容更清楚):
sysinfo [column]
miscInfo ; vendor: aaa ; bootr: bbb; revision: ccc; model: ddd [string a]
miscInfo ; vendor: aaa ; bootr: bbb; revision: ccc; model: ddd [string b]
...
There are a little over one million entries with the string that looks like this. 看起来像这样的字符串大约有一百万条。 Is it possible in mySQL so that the query returns the following
在mySQL中是否可能,以便查询返回以下内容
miscInfo, Vendor, Bootr, Revision , Model [columns]
miscInfo_a, vendor_a, bootr_a, revision_a, model_a
miscInfo_b, vendor_b, bootr_b, revision_b, model_b
...
for all of the rows in the table, where the comma indicates a new column? 对于表中的所有行,逗号表示新列?
Edit: 编辑:
Here's some input and output as Bohemian requested. 以下是Bohemian要求的一些输入和输出。
sysinfo [column]
Modem <<HW_REV: 04; VENDOR: Arris ; BOOTR: 6.xx; SW_REV: 5.2.xxC; MODEL: TM602G>>
<<HW_REV: 1; VENDOR: Motorola ; BOOTR: 216; SW_REV: 2.4.1.5; MODEL: SB5101>>
Thomson DOCSIS Cable Modem <<HW_REV: 4.0; VENDOR: Thomson; BOOTR: 2.1.6d; SW_REV: ST52.01.02; MODEL: DCM425>>
Some can be longer entries but they all have similar format. 有些条目可以是更长的条目,但它们都具有相似的格式。 Here is what I would like the output to be:
这是我想要的输出:
miscInfo, vendor, bootr, revision, model [columns]
04, Arris, 6.xx, 5.2.xxC, TM602G
1, Motorola, 216, 2.4.1.5, SB5101
4.0, Thomson, 2.1.6d, ST52.01.02, DCM425
Please take a look at how I've split my coordinates column into 2 lat/lng columns: 请查看我如何将坐标列分为2个经/纬度列:
UPDATE shops_locations L
LEFT JOIN shops_locations L2 ON L2.id = L.id
SET L.coord_lat = SUBSTRING(L2.coordinates, 1, LOCATE('|', L2.coordinates) - 1),
L.coord_lng = SUBSTRING(L2.coordinates, LOCATE('|', L2.coordinates) + 1)
In overall I followed UPDATE JOIN
advice from here MySQL - UPDATE query based on SELECT Query and STR_SPLIT
question here Split value from one field to two 总的来说,我遵循这里的
UPDATE JOIN
建议STR_SPLIT
基于SELECT查询和STR_SPLIT
问题的UPDATE查询这里的值从一个字段拆分为两个
Yes I'm just splitting into 2, and SUBSTRING might not work well for you, but anyway, hope this helps :) 是的,我只是一分为二,SUBSTRING可能对您而言效果不佳,但是无论如何,希望这会有所帮助:)
您可以在mysql中使用String函数(尤其是substr ): http : //dev.mysql.com/doc/refman/5.0/en/string-functions.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.