MySQL Second (or third) Index Of in String

后端 未结 5 1483
隐瞒了意图╮
隐瞒了意图╮ 2020-12-15 18:19

What would be the simplest way to locate the index of the third space in a string.

My goal is to get CCC out of this space separated list: AAAA BB

5条回答
  •  無奈伤痛
    2020-12-15 19:04

    Generally you can select the nth word in a string using:

    SET @N = 3; -- 3rd word
    SET @delimiter = ' ';
    SELECT
      SUBSTRING_INDEX(SUBSTRING_INDEX(words, @delimiter, @N), @delimiter, -1)
    FROM
      my_table
    

提交回复
热议问题