【问题标题】:MYSQL - get value from position of comma-separated-stringMYSQL - 从逗号分隔字符串的位置获取值
【发布时间】:2017-07-22 11:35:05
【问题描述】:

我的表中有这样一个字段:

fox,cat,bear,horse,dog

使用 FIND_IN_SET 我可以找到该值是否在该字符串中并取回它的位置。 有没有办法获得确定位置的价值?

例如:

position 3 = bear
position 2 = cat

【问题讨论】:

    标签: mysql find-in-set


    【解决方案1】:

    您可以通过这种方式使用 substring_index 两次(将 2 更改为您要提取的任何项目):

    select substring_index(substring_index(col, ',', 2), ',', - 1)
    from t
    

    Demo

    【讨论】:

      猜你喜欢
      • 2011-09-07
      • 2014-03-22
      • 2019-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-04
      • 2012-05-19
      • 1970-01-01
      相关资源
      最近更新 更多