分组函数和前面讲的函数不同在于,前面的对内容本身的处理,而分组函数的主要功能是统计。
主要讲的分组函数:sum , avg , max , min , count
select sum(salary) as 单月所发总工资 from employees;
select avg(salary) as 单月所发平均工资 from employees;
select max(salary) as 单月所发最多工资 from employees;
select min(salary) as 单月所发最少工资 from employees;
select count(*) as 总员工人数 from employees; //count(*) 用来统计行数
分组函数的共同特点:会忽略null
分组函数还可以和一个关键字和用:distinct
select count(distinct salary) from employees;