四、group function 组函数

  

  

    -| max函数,求最大值

    -| min函数,求最小值

    -| avg函数,求平均值

    -| count函数

    -| sum函数

    

    e.g:

      select to_char(avg(sal),'99999999,99') from emp;

      求sal中的平均值并精确到小数点后两位小数

      select round(avg(sal),2) from emp;
      结果:2073.21


      select count(*) from emp where deptno=10;
      select count(ename) from emp where deptno=10; count某个字段,如果这个字段不为空就算一个.
      select count(distinct deptno) from emp;


      select sum(sal) from emp;

 

 

 

五、 group  by 语句

    


    需求:现在想求,求每个部门的平均薪水.
      select avg(sal) from emp group by deptno;
      select deptno avg(sal) from emp group by deptno;

      select deptno,job,max(sal) from emp group by deptno,job;

      求薪水值最高的人的名字.
      select ename,max(sal) from emp;出错,因为max只有一个值,但等于max值的人可能好几个,不能匹配.
      应如下求:

  

      select ename from emp where sal=(select max(sal) from emp);

      Group by语句应注意,

      出现在select中的字段,如果没出现在组函数中,必须出现在Group by语句中.

相关文章:

  • 2022-12-23
  • 2021-11-27
  • 2022-02-07
  • 2021-09-29
  • 2022-12-23
  • 2021-07-05
  • 2021-10-19
  • 2022-02-28
猜你喜欢
  • 2021-11-12
  • 2022-01-03
  • 2021-11-17
  • 2022-02-20
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案