常用组函数:
1.ccount() 求出全部记录数。 2.max() 求出一组最大值 3.min() 求出一组最小值 4.avg() 求出平均值 5.sum() 求和--1.统计员工数量: select count(empno) from emp; --2.求出最高薪资 select max(sal) from emp; --3.求出最低薪资 select min(sal) from emp; --4.求出平均薪资 select avg(sal) from emp; --查询各部门员工数量 select deptno,count(empno) from emp group by deptno --查询各部门平均工资 select deptno,avg(sal) from emp group by deptno --注意:分组函数只能单独使用,或者指定分组条件,这样可以将分组条件查询出来。 select empno,count(sal) from emp;---无法执行 select deptno,avg(sal) from emp where avg(sal) >2000 group by deptno--无法执行 ----注意:分组函数不能作为条件在hwere中使用,只能在having中使用。 select deptno,avg(sal) from emp group by deptno having avg(sal) >2000 select max(avg(sal)) from emp group by deptno;--嵌套的分组函数只能单独使用 --查询非销售人员的工作名称,以及从事同一个工作的人员薪资总和,并且要满足从事同一个工作的工作总和大于5000,安排工资合计升序。 select job ,sum(sal) su from emp where job <> 'SALESMAN' group by job having sum(sal) >5000 order by su;