为此,请使用SUBSTRING_INDEX()。让我们首先创建一个表-create table DemoTable1615
-> (
-> ListOfSubject text
-> );
使用插入命令在表中插入一些记录-insert into DemoTable1615 values('Python,Java,MySQL,MongoDB,C,C++,ASP.net');
使用select语句显示表中的所有记录-select * from DemoTable1615;
这将产生以下输出-+-----------------------------------------+
| ListOfSubject |
+-----------------------------------------+
| Python,Java,MySQL,MongoDB,C,C++,ASP.net |
+-----------------------------------------+
1 row in set (0.00 sec)
这是从逗号分隔字符串的位置获取单个值的查询-select substring_index(substring_index(ListOfSubject, ',', 4), ',', - 1) as Position from DemoTable1615;
这将产生以下输出-+----------+
| Position |
+----------+
| MongoDB |
+----------+
1 row in set (0.00 sec)