MySQL的SUBSTRING_INDEX方法
参数说明:
substring_index(str,delimiter,count)
1.str:需要拆分的字符串
2.delimiter:分隔符(记得引号)
3.count:第几个分隔符(分正负数)
count为正数时,str字符从左往右数第count个delimiter,截止,左边全部内容为截取内容。
count为负数时,str字符从右往左数第count的绝对值个delimiter,截止,右边边全部内容为截取内容。
示例:
str = "ab,cd,ef,gh";
substring_index(str,",",2) = "ab,cd";
substring_index(str,",",-3) = "cd,ef,gh";