MYSQL针对于行多个字段转成多行的处理

mysql中,经常出现某个字段值以逗号分隔,存在数据库中,当需要针对此值进行查询时。就比较难处理

针对于场景,mysql提供substring_index进行操作

详细sql如下:

SELECT mobile from a where customer_no in(
SELECT
DISTINCT substring_index(
substring_index(
a.customer_nos,
',',
b.id + 1
),
',' ,- 1
) AS shareholder
FROM
table_b  a
JOIN (SELECT id from table_c where id <2001) b ON a.customer_collection_id='610' and b.id < 2001 ) and mobile is not null ;

可以确认最大的分隔数据2001,即可将此数据进行处理


原文地址:https://www.cnblogs.com/cbliu/p/13292721.html