zoukankan      html  css  js  c++  java
  • Oracle_多行函数

     

    Oracle_多行函数

     

    多行函数min(),max(),count(),sum(),avg()
    --1.1统计公司的最高工资,最低工资和总人数
    --对于null值直接略过,不做运算
    --max,min,count可以对任意类型进行操作
    select max(sal), min(sal),count(empno) from emp;
    select max(sal), min(sal),count(comm) from emp;
    select max(sal), min(sal),count(mgr) from emp;
     
    select sum(comm), avg(comm) from emp;
     
    select max(ename), min(hiredate) from emp;  
    --2.统计emp表中的记录数
    select count(*) from emp;
     
    --2.1统计部门编号为10的部门员工总数
     select count(*) from emp where deptno=10;  
    --3.分组group by,    order by永远放在最后
    --统计每个部门的部门编号,员工人数,并按照部门编号进行排序
    select deptno, count(*) from emp group by deptno order by deptno;
     
    --3.1查询各个部门的编号,人数,总工资,平均工资,最高工资,最低工资
    select  deptno, count(*), sum(sal), avg(sal), max(sal), min(sal) from emp group by deptno order by avg (sal);
    select count(*), sum(sal), avg(sal), max(sal), min(sal) from emp group by deptno order by avg (sal);
     
    --3.2统计每个部门的人数,排除编号为30的部门
    --先写where子句,后写group by
    select deptno, count(*) from emp where deptno<>30 group by deptno;  
    -4.统计每个部门的平均工资,排除平均工资小于2000的部门
    --where子句中不允许使用多行函数
    --having分组完成后,进行筛选(不能使用别名进行判断),having的语法和where基本一致
    select deptno, avg(sal) from emp group by deptno having avg(sal)>=2000;
    select deptno, avg(sal) from emp group by deptno having avg(sal)>=2000 and deptno<>10;  
    练习
    --在emp表中,列出工资最小值小于2000的职位
    select job,min(sal) from emp group by job having min(sal)<2000;
     
     
    --列出平均工资大于1200的部门和工作搭配的组合
    select deptno,job,avg(sal) from emp group by deptno,job having avg(sal)>1200;  

    --统计人数小于4的部门的平均工资
    select deptno,avg(sal),count(*) from emp group by deptno having count(*)<4;
     
     
    --统计各部门的最高工资,排除最高工资小于3000的部门
    select from emp group by deptno having max(sal)>3000;  



     
  • 相关阅读:
    Multi-Agent Actor-Critic for Mixed Cooperative-Competitive Environments环境代码详解
    zc.buildout构建项目时报错‘AttributeError: '_NamespacePath' object has no attribute 'sort'’
    利用Jenkins打包ISO和QCOW2镜像文件
    解决python pip安装提示"not a supported wheel on this platform"
    Kali 2017.3开启VNC远程桌面登录
    Jenkins邮件扩展插件Email Extension Plugin配置使用
    Jenkins执行sudo权限的设置
    如何解决源码安装软件中make时一直重复打印configure信息
    CentOS 7下安装配置proftpd搭建ftp服务器
    如何使用capedit分割数据包文件
  • 原文地址:https://www.cnblogs.com/haozhengfei/p/6538385.html
Copyright © 2011-2022 走看看