mysql同一表記錄某一字段內容合並 mysql> create table t(id int,name varchar(20)); Query OK, 0 rows affected (0.09 sec) www.2cto.com mysql> insert into t values (1,'aa'),(1,'bb'),(2,'cc'),(2,'dd'); Query OK, 4 rows affected (0.00 sec) Records: 4 Duplicates: 0 Warnings: 0 mysql> commit; Query OK, 0 rows affected (0.00 sec) mysql> select * from t; +------+------+ | id | name | +------+------+ | 1 | aa | | 1 | bb | | 2 | cc | | 2 | dd | +------+------+ 4 rows in set (0.01 sec) mysql> select id,GROUP_CONCAT(name) from t group by id; +------+--------------------+ | id | GROUP_CONCAT(name) | +------+--------------------+ | 1 | aa,bb | | 2 | cc,dd | +------+--------------------+ 2 rows in set (0.00 sec)