MySQL Second (or third) Index Of in String

后端 未结 5 1504
隐瞒了意图╮
隐瞒了意图╮ 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:12

    You would want to use SUBSTRING_INDEX function like this

    SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(field, ' ', 3), ' ', -1)
    FROM table
    

    The inner function call would get you to AAAA BBBB CCCC while the outer function call would pare that down to just CCCC.

提交回复
热议问题