-- group_concat();
create table gc(
id int not null auto_increment,
sex tinyint ,
name varchar(10),
primary key (id)
);
insert into gc values(null,0,'小明');
insert into gc values(null,1,'小红');
insert into gc values(null,0,'小光');
insert into gc values(null,0,'小男');
insert into gc values(null,1,'小青');
insert into gc values(null,1,'春开');
select * from gc group by sex;
select id,sex,name from gc group by sex;
-- 按sex分组后,显示所有name
select id,sex,group_concat(name) from gc group by sex;
select id,sex,group_concat(name order by name desc separator ';') from gc group by sex;
select id,sex,group_concat(name separator ';') from gc group by sex;
-- group_concat不是只能用在有group by 的语句,只要结果返回多行就可以.他是将多行聚合为一行返回结果
select id,name,group_concat(name) from stus where age>22;
---------------------
作者:qq_35517542
来源:CSDN
原文:https://blog.csdn.net/qq_35517542/article/details/51852543
版权声明:本文为博主原创文章,转载请附上博文链接!