略
正向截取字符串
mysql> select substring_index('www.baidu.com','.',1);
+----------------------------------------+
| substring_index('www.baidu.com','.',1) |
+----------------------------------------+
| www |
+----------------------------------------+
1 row in set (0.02 sec)
mysql> select substring_index('www.baidu.com','.',2);
+----------------------------------------+
| substring_index('www.baidu.com','.',2) |
+----------------------------------------+
| www.baidu |
+----------------------------------------+
1 row in set (0.02 sec)
mysql> select substring_index('www.baidu.com','.',3);
+----------------------------------------+
| substring_index('www.baidu.com','.',3) |
+----------------------------------------+
| www.baidu.com |
+----------------------------------------+
1 row in set (0.02 sec)
mysql> select substring_index('www.baidu.com','.',4);
+----------------------------------------+
| substring_index('www.baidu.com','.',4) |
+----------------------------------------+
| www.baidu.com |
+----------------------------------------+
1 row in set (0.02 sec)
逆向截取字符串
mysql> select substring_index('www.baidu.com','.',-1);
+-----------------------------------------+
| substring_index('www.baidu.com','.',-1) |
+-----------------------------------------+
| com |
+-----------------------------------------+
1 row in set (0.02 sec)
mysql> select substring_index('www.baidu.com','.',-2);
+-----------------------------------------+
| substring_index('www.baidu.com','.',-2) |
+-----------------------------------------+
| baidu.com |
+-----------------------------------------+
1 row in set (0.02 sec)
mysql> select substring_index('www.baidu.com','.',-3);
+-----------------------------------------+
| substring_index('www.baidu.com','.',-3) |
+-----------------------------------------+
| www.baidu.com |
+-----------------------------------------+
1 row in set (0.02 sec)
mysql> select substring_index('www.baidu.com','.',-4);
+-----------------------------------------+
| substring_index('www.baidu.com','.',-4) |
+-----------------------------------------+
| www.baidu.com |
+-----------------------------------------+
1 row in set (0.02 sec)
mysql> select substring_index('www.baidu.com', '.', 1);
+------------------------------------------+
| substring_index('www.baidu.com', '.', 1) |
+------------------------------------------+
| www |
+------------------------------------------+
1 row in set (0.02 sec)
mysql> select substring_index(substring_index('www.baidu.com', '.', 2), '.', -1);
+--------------------------------------------------------------------+
| substring_index(substring_index('www.baidu.com', '.', 2), '.', -1) |
+--------------------------------------------------------------------+
| baidu |
+--------------------------------------------------------------------+
1 row in set (0.02 sec)
mysql> select substring_index(substring_index('www.baidu.com', '.', 3), '.', -1);
+--------------------------------------------------------------------+
| substring_index(substring_index('www.baidu.com', '.', 3), '.', -1) |
+--------------------------------------------------------------------+
| com |
+--------------------------------------------------------------------+
1 row in set (0.02 sec)