8 group by 约束条件

Posted zhujing666

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 约束条件的主要内容,如果未能解决你的问题,请参考以下文章

Group_by,条件求和并替换R中的变量

关于C#中group by如何实现多条件分组汇总

r - 使用 group_by 和 mutate 根据多个条件添加新列时出现意外的“=”

SQL中where和group by可以连用吗?having算是对检索条件的补充吗?

使用 group_by 后根据条件转换哈希值

SQL语句中,如果有group by 和order by两个语句,是先分组还是先排序?