Mysql group_concat()

1. 表格内容

 

 

2.  分组查询,查出各部门人数,以及各部门员工姓名

select edept,count(*),group_concat(ename) from emp_info a group by edept;

 

 

3. 分组查询,查出各部门人数,以及各部门员工姓名,salary,kpi

查询1:

 

select edept,count(*),group_concat(ename,salary,kpi) from emp_info a group by edept;

结果1:

 

 

查询2:

select edept,count(*),group_concat(ename," ",salary," ",kpi) from emp_info a group by edept;

结果2:

 

示例3:

select edept , group_concat(ename) from emp_info group by edept having avg(salary)>5000;

 

结果3:

 

 

查询4:

select group_concat(ename) from emp_info;

 

结果4:

 

 

查询5:

select group_concat(ename) from emp_info where salary > 4000;

 

结果5:

 

 

  

posted @ 2021-07-15 21:38  Avicii_2018  阅读(62)  评论(0编辑  收藏  举报