我的数据库中有一个包含X个条目的字段。我想拆分这些条目,按字母顺序对它们进行排序,然后重新连接它们。
CREATE TABLE `crates`(`crate` int(2), `fruit` varchar(255) DEFAULT NULL, PRIMARY KEY `crate`);
INSERT INTO crates VALUES(1,'apples');
INSERT INTO crates VALUES(2,'lemons,apples');
INSERT INTO crates VALUES(3,'lemons,bananas,apples');
所以我得到了:
mysql> SELECT * FROM crates;
+-------+-----------------------+
| crate | fruit |
+-------+-----------------------+
| 1 | apples |
| 2 | lemons,apples |
| 3 | lemons,bananas,apples |
+-------+-----------------------+
我希望这是我的结果:
+-------+-----------------------+
| crate | fruit |
+-------+-----------------------+
| 1 | apples |
| 2 | apples,lemons |
| 3 | apples,bananas,lemons |
+-------+-----------------------+
字段fruit
中的项目数未知。