注意:聚合函数要用HAVING来过滤
聚合函数:
--min:最小值
--max:最大值
--字符类型
select max(ename)
from emp;
--数值类型:
select min(sal)
from emp;
--日期类型
select min(hiredate)
from emp;
--sum:求和
--avg:求平均值
select sum(sal) 和,avg(sal) 平均值
from emp;
--count:返回总记录数
select count(*)
from emp;
select count(comm)
from emp;
--过滤空值:
--只有count(*)不过滤空值
group by:用来分组,比如:group by deptno
--可以把表中的数据分成指定小组
--查询每个部门的编号,平均工资
select deptno,avg(sal),ename
from emp
group by deptno,ename;
--注意:在select子句后面除了聚合函数,其他的列都要出现在group by子句后面
--注意:在group by后面出现的列不一定要出现在select后面
having:写在group by 的后面,where写在group by的前面
--应用场景:用来过滤分组函数
--除了聚合函数,其他的条件过滤都要写在where子句中
来源:CSDN
作者:এ᭄小小常
链接:https://blog.csdn.net/weixin_45721343/article/details/103993789