假如有表A
id     name
1        a,b,c
2        a,b
3        e,g
想把name字段以逗号分隔开显示成多列,要得到这样的结果
id     name
1      a
1      b
1      c
2      a
2      b
3      e
3      g
请问各位大神们怎么办,谢谢了

解决方案 »

  1.   

    加入辅助表,辅助表如下
    create table flag(
    name varchar(1)
    )
    在flag表中存储表A中可能出现的所有字符根据你的例子需要如下初始化
    insert into flag select 'a';
    insert into flag select 'b';
    insert into flag select 'c';
    insert into flag select 'e';
    insert into flag select 'g';查询语句为
    select id,flag.name from A, flag where find_in_set(flag.name,A.name) > 0 order by id