8 group by 约束条件

select post from employee group by post; # 只能取分组的字段

#聚合函数 
max
min
avg
sum
count

#每个职位有多少个员工
select post,count(id) from employee group by post;
select post,count(id) as emp_count from employee group by post;

select post,max(salary) as emp_count from employee group by post;
select post,min(salary) as emp_count from employee group by post;
select post,avg(salary) as emp_count from employee group by post;
select post,sum(age) as emp_count from employee group by post;

select post,group_concat(id,name) from employee group by post;

 

你可能感兴趣的:(8 group by 约束条件)