【问题标题】:Return rows with more than one comma separated value in a string返回字符串中包含多个逗号分隔值的行
【发布时间】:2015-03-13 18:24:52
【问题描述】:

我有一个名为contacts 的表,在该表中有一个名为contact_type 的字段。

contact_type 是 varchar 并将逗号分隔的值存储在这样的字符串中:

^Media^,^Historical^

但是,数千行中只有几行存储了多个值,我需要运行一个查询,该查询将仅返回具有多个值的行,因此如果它仅存储 ^Historical^,那么它将被忽略。

我对如何构建这样的查询感到非常困惑。我认为它将包含以下内容:

SELECT LENGTH(@css) - LENGTH( REPLACE( @css, ',', '') ) + 1;

【问题讨论】:

    标签: mysql sql


    【解决方案1】:

    基本上你需要选择contact_type包含逗号的记录

    select * from your_table
    where instr(contact_type, ',') > 0
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-28
      相关资源
      最近更新 更多