在MySQL中,将一列集合值转换为一列单个值
我继承了一个表,其中一列是另一个表的主键的逗号分隔列表: id | other_ids | value ---|-----------|------- 1 | a,b,c | 100 2 | d,e | 200 3 | f,g | 3000 然而,我想不出一个办法来做到这一点在MySQL中,将一列集合值转换为一列单个值,mysql,sql,Mysql,Sql,我继承了一个表,其中一列是另一个表的主键的逗号分隔列表: id | other_ids | value ---|-----------|------- 1 | a,b,c | 100 2 | d,e | 200 3 | f,g | 3000 然而,我想不出一个办法来做到这一点 该表的大小大于10 GB,因此如果可能,我希望在数据库中执行此操作。如果您有另一个表,则可以使用连接和在集合中查找(): 如果有另一个表,则可以使用联接和在集合中查找(): 第一次邮寄
该表的大小大于10 GB,因此如果可能,我希望在数据库中执行此操作。如果您有另一个表,则可以使用
连接和在集合中查找()
:
如果有另一个表,则可以使用联接和在集合中查找()
:
第一次邮寄,请友好
试试这个
select id,SUBSTRING_INDEX(other_ids,',',1) as other_id from reverseconcat
UNION
select id,SUBSTRING_INDEX(SUBSTRING_INDEX(other_ids,',',2),',',-1) as other_id from reverseconcat
UNION
select id,SUBSTRING_INDEX(SUBSTRING_INDEX(other_ids,',',3),',',-1) as other_id from reverseconcat
order by id
虽然我真的不能接受任何信用。找到这个了吗
不确定如何处理庞大的数据集。另外,如果其他ID在第一次发布时大于3,您需要添加更多的联合,请友好
试试这个
select id,SUBSTRING_INDEX(other_ids,',',1) as other_id from reverseconcat
UNION
select id,SUBSTRING_INDEX(SUBSTRING_INDEX(other_ids,',',2),',',-1) as other_id from reverseconcat
UNION
select id,SUBSTRING_INDEX(SUBSTRING_INDEX(other_ids,',',3),',',-1) as other_id from reverseconcat
order by id
虽然我真的不能接受任何信用。找到这个了吗
不确定如何处理庞大的数据集。另外,如果其他_id>3,则需要添加更多的联合
select id,SUBSTRING_INDEX(other_ids,',',1) as other_id from reverseconcat
UNION
select id,SUBSTRING_INDEX(SUBSTRING_INDEX(other_ids,',',2),',',-1) as other_id from reverseconcat
UNION
select id,SUBSTRING_INDEX(SUBSTRING_INDEX(other_ids,',',3),',',-1) as other_id from reverseconcat
order by id