zoukankan      html  css  js  c++  java
  • 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语句中.

  • 相关阅读:
    使用powerdesigner导入sql脚本,生成物理模型
    深入理解[代理模式]原理与技术
    8、Dockerfile介绍和最佳实践
    7、Docker监控方案(cAdvisor+InfluxDB+Grafana)
    6、Docker图形化管理(Portainer)
    5、Docker网络配置(单机)
    4、Docker数据管理
    html二
    html
    IO多路复用,协程,
  • 原文地址:https://www.cnblogs.com/elleniou/p/2625620.html
Copyright © 2011-2022 走看看