从逗号分隔的单个字符串中查找不同的值

时间:2014-03-28 18:58:30

标签: mysql

我有一个这样的表,我想在单列中选择不同的值:

  ID        Value

  1       13245|43558

  2       45961|5051

  3       43558| 5059

我需要输出像这样:

13245,43558,45961,5051,5059

2 个答案:

答案 0 :(得分:1)

试试:

  select group_concat(distinct trim(substring_index(substring_index(value, '|', n.n), '|', -1)) separator ',' ) as `values`
  from table1 t 
  cross join (select 1 as n union all select 2 ) n
  order by `values`

DEMO HERE

答案 1 :(得分:0)

尝试此查询:

SELECT GROUP_CONCAT(distinct(Value)) from table;