___聚合函数___max():最大值min():最小值avg():平均值sum():和count():记数
group_concat():组内字段拼接,用来查看组内其他字段
___example___
# eg1
# 每个部门的平均薪资
select dep, avg(salary) '平均薪资' from emp group by dep;
mysql> select dep, avg(salary) '平均薪资' from emp group by dep;
+-----------+-------------------+
| dep | 平均薪资 |
+-----------+-------------------+
| 咨询部 | 6.250000059604645 |
| 人资部 | 5.400000027247837 |
| 技术部 | 5.850000023841858 |
+-----------+-------------------+
3 rows in set (0.00 sec)
# eg:2
# 每个部门都有哪些人
select dep, group_concat(name) 'name' from emp group by dep;
mysql> select dep,group_concat(name) 'name' from emp group by dep;
+-----------+---------------------------------------+
| dep | name |
+-----------+---------------------------------------+
| 咨询部 | san1,san,ying,zero |
| 技术部 | san2,kevin,owen,jiboy,tank,jerry,engo |
| 人资部 | monkey,yangsir |
+-----------+---------------------------------------+
3 rows in set (0.04 sec)
# eg3
# 各性别中附属于教学部的最高薪资
select max(salary) '最高薪资', gender from emp where dep='教学部' group by gender;