求指导答 MySQL 数据库存储的是带有逗号的字段,查出来之后怎么分隔

MySql 码拜 8年前 (2016-02-08) 915次浏览
列如 字段是 小明,小红
本人要获取的是
ID   name
1     小明
1     小红
解决方案

10

SET @b =  “小明,小红”;
SET @a = REPLACE(@b,”,”, ” union all select “);
SET @a = CONCAT(“select “, @a);
PREPARE rc FROM @a;
EXECUTE rc;

10

mysql> select id,substring_index(name,”,”,1) name from xm union all select id,reverse(substring_index(reverse(name),”,”,1)) name from xm;
+–+–+
| id   | name   |
+–+–+
|    1 | 小明   |
|    1 | 小红   |
+–+–+
2 rows in set (0.00 sec)

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明求指导答 MySQL 数据库存储的是带有逗号的字段,查出来之后怎么分隔
喜欢 (0)
[1034331897@qq.com]
分享 (0)