MySQL里group_concat函数的含义

MySQL里这个函数主要是在group时能看出它的作用,一般在我们使用group by时,同样的数据,只会显示一条,但某些时刻,我们却需要把同样的数据进行规类到一起,那么group_concat这个函数就派上用场了,例子如下:
CREATE TABLE test(
id int(11) unsigned not null auto_increment,
pid int(11) unsigned not null,
name varchar(20) not null,
primary key(id)
)ENGING=myisam default charset=utf8;
insert into `test`(`pid`, `name`) values (1, 'z1');
insert into `test`(`pid`, `name`) values (1, 'z2');
insert into `test`(`pid`, `name`) values (1, 'z3');
insert into `test`(`pid`, `name`) values (2, 'z4');
table name is test
id pid name
1 1 z1
2 1 z2
3 1 z3
4 2 z4
select name from test group by pid;
select group_concat(name) as name from test group by pid;