2

例如这是我的表(复制)。

id  customer        product 
1   Tizag           Pen 
4   Gerald Garner   19" LCD Screen  
5   Tizag           19" LCD Screen  
6   Gerald Garner   clock

我想选择整个表。结果必须是这样的:

customer        product 
Tizag           Pen,19" LCD Screen
Gerald Garner   19" LCD Screen,clock

我怎样才能做到这一点?

4

2 回答 2

3
Select customer ,
Group_Concat(product SEPARATOR ',') as Product
from TableName group by customer    

SQL 小提琴演示

于 2013-09-18T06:37:22.190 回答
1

无需使用“,”作为分隔符,默认自带

 select customer, group_concat(product) as product
 from tableName
 group by customer
于 2013-09-18T06:38:57.377 回答