0
点赞
收藏
分享

微信扫一扫

MySQL的分组函数

毅会 2024-11-08 阅读 15

分组函数和前面讲的函数不同在于,前面的对内容本身的处理,而分组函数的主要功能是统计。

主要讲的分组函数: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;
举报

相关推荐

0 条评论