MYSQL - 从逗号分隔字符串的位置获取值

MYSQL - get value from position of comma-separated-string

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

fox,cat,bear,horse,dog

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

例如:

position 3 = bear
position 2 = cat

这样可以使用substring_index两次(把2改成你想提取的项目):

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

Demo