贴上简单的例子:
mysql SELECT * FROM `ta`;
+----+------+
| id | name |
+----+------+
| 1 | a |
| 1 | b |
| 1 | c |
| 1 | d |
| 2 | a |
| 2 | b |
| 2 | c |
| 3 | d |
+----+------+
8 rows in set (0.00 sec)
mysql SELECT `id`,
- GROUP_CONCAT(`name`)
- FROM `ta`
- GROUP BY `id`;
+----+----------------------+
| id | GROUP_CONCAT(`name`) |
+----+----------------------+
| 1 | a c b d |
| 2 | a c b |
| 3 | d |
+----+----------------------+
3 rows in set (0.03 sec)
转自:http://bbs.phpso.com/journal.php?do=showentry&e=76
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/bianchengyuyan/)