MySQL 用 ID 拆分出一列
MySQL split a column out with ID
我希望将我的 MySQL 列之一分开,因为它是由用 ,(逗号)分隔的单词组成的。我需要在 (,) 上拆分数据并收集相应的 ID,以便将其放入另一个 table。最简单的方法是什么。
例如发件人:当前
frog -- Table
ID common_name
1 Yellow-spotted Tree Frog, Yellow-spotted Bell Frog
收件人:
common_name_frog -- Table
Frog_id Common_name
1 Yellow-spotted Tree Frog
1 Yellow-spotted Bell Frog
一种方法是导出数据并使用其他工具。如果字符串不是太长,你可以这样做:
create table common_name_frog as
select f.id,
substring_index(substring_index(common_name, ', ', n.n), ', ', -1) as Common_name
from (select 1 as n union all select 2 union all select 3) n join
frog f
on n.n <= length(common_name) - length(replace(common_name, ',', '')) + 1;
我希望将我的 MySQL 列之一分开,因为它是由用 ,(逗号)分隔的单词组成的。我需要在 (,) 上拆分数据并收集相应的 ID,以便将其放入另一个 table。最简单的方法是什么。
例如发件人:当前
frog -- Table
ID common_name
1 Yellow-spotted Tree Frog, Yellow-spotted Bell Frog
收件人:
common_name_frog -- Table
Frog_id Common_name
1 Yellow-spotted Tree Frog
1 Yellow-spotted Bell Frog
一种方法是导出数据并使用其他工具。如果字符串不是太长,你可以这样做:
create table common_name_frog as
select f.id,
substring_index(substring_index(common_name, ', ', n.n), ', ', -1) as Common_name
from (select 1 as n union all select 2 union all select 3) n join
frog f
on n.n <= length(common_name) - length(replace(common_name, ',', '')) + 1;