列如 字段是 小明,小红
本人要获取的是
ID name
1 小明
1 小红
本人要获取的是
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;
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)
+–+–+
| id | name |
+–+–+
| 1 | 小明 |
| 1 | 小红 |
+–+–+
2 rows in set (0.00 sec)