我有两张桌子 testa
和testb
.
mysql> select * from testa;
+------+-------+
| id | dcac |
+------+-------+
| 1 | hello |
| 2 | world |
+------+-------+
2 rows in set (0.00 sec)
mysql> select * from testb;
+------+------+
| a_id | x |
+------+------+
| 1 | a |
| 1 | b |
| 1 | b |
| 1 | c |
| 2 | x |
+------+------+
5 rows in set (0.00 sec)
如何添加一列 ( x_list
) 使其成为stesta
的逗号分隔列表x
testb
testa.id
testb.a_id
所以我期待的输出有点像这样 -
+------+-------+--------+
| id | dcac | x-list |
+------+-------+--------+
| 1 | hello | a,b,b,c|
| 2 | world | x |
+------+-------+--------+
我尝试使用一些复杂join
的语句,并查看了这个http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat(不太了解)
但我无法继续。我该怎么办?谢谢。