关于mysql的substring_index函数

函数说明:
SUBSTRING_INDEX(str,delim,count) 返回字符串 str 中在第 count 个出现的分隔符 delim 之前的子串。如果 count 是一个正数,返回从最后的(从左边开始计数)分隔符到左边所有字符。如果 count 是负数,返回从最后的(从右边开始计数)分隔符到右边所有字符。


举例:
[color=darkblue][/color]
mysql> select postId,substring_index(postId,'|',2) from user_resumetbl order by id desc limit 10;
+------------+-------------------------------+
| postId     | substring_index(postId,'|',2) |
+------------+-------------------------------+
| |79        | |79                           |
| |76|36|42  | |76                           |
| |672|66|73 | |672                          |

说明:
以上例子中substring_index(postId,'|',2)意思是,返回postId字段中第二个出现“|”字符的左边的字符串

你可能感兴趣的:(substring)