• Oracle学习<三>


    四、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语句中.

  • 相关阅读:
    shell脚本使用记录一:操作文件
    用IDEA在Tomcat上部署项目
    通过反射获取属性名和属性类型
    IDEA设置生成类基本注释信息
    有序的Map集合--LinkedHashMap
    书面格式注意的问题
    悲观锁和乐观锁的区别
    解析xml文件的四种方式
    jsp的四种范围
    jsp的两种跳转方式和区别
  • 原文地址:https://www.cnblogs.com/elleniou/p/2625620.html
Copyright © 2020-2023  润新知