如下所示数据组成,我想按姓名分组组成结果形式:oyy 23#24#25#26.
mysql> select * from student;
+----+------------------+------+
| id | name | age |
+----+------------------+------+
| 1 | C34A89EC57276F7C | 33 |
| 2 | 315134Y | 75 |
| 3 | Z54ZX4Z | 39 |
| 4 | oyy | 23 |
| 5 | zyy | 22 |
| 6 | oyy | 24 |
| 7 | oyy | 25 |
| 8 | oyy | 26 |
+----+------------------+------+
可以使用mysql的函数group_concat(字段 SEPARATOR字符):
mysql> select name, GROUP_CONCAT( age SEPARATOR '#') from student group by name;
+------------------+---------------------------------------+
| name | GROUP_CONCAT( age SEPARATOR '#') |
+------------------+---------------------------------------+
| 315134Y | 75 |
| C34A89EC57276F7C | 33 |
| oyy | 23#24#25#26 |
| Z54ZX4Z | 39 |
| zyy | 22 |
+------------------+----------------------------------+