zoukankan      html  css  js  c++  java
  • 006 group by having

    /*
    时间:2020/09/09
    功能:
        一 group by 
        二 having
    */  

    一 group by

    select deptno, max(sal) "max", min(sal) "min", 
        avg(sal) "avg", sum(sal) "sum", 
        count(*) "all count", count(sal) "not null count" 
        from emp
        group by deptno

    select deptno, job
        from emp
        group by deptno, job

    select deptno, job, ename, mgr
        from emp
        group by deptno, job, ename, mgr

    select deptno, job, min(sal) "部门最低工资", max(sal) "部门最高工资", 
        sum(sal) "部门总工资", avg(sal)"平均工资", count(*) "部门人数"
        from emp
        group by deptno, job
        order by deptno, job

    二 having

    --把姓名不包含A的所有的员工按部门编号分组,
    --统计输出部门平均工资大于2000的部门的部门编号 部门的平均工资
    select deptno, avg(sal)
        from emp
        where ename not like '%a%'
        group by deptno
        having avg(sal) > 2000
    
    
    --把工资大于2000,
    --统计输出部门平均工资大于3000的部门的部门编号 部门的平均工资
    select deptno, avg(sal)
        from emp
        where sal > 2000
        group by deptno
        having avg(sal) > 3000

    select deptno, job, avg(sal)
        from emp
        where hiredate >= '1981-05-01'
        group by deptno, job
        having deptno > 10
        order by deptno, job
    
    select deptno, job, avg(sal)
        from emp
        where hiredate >= '1981-05-01'
        group by deptno, job
        having job like '%s%'
        order by deptno, job

  • 相关阅读:
    php 人员权限管理(RBAC)
    CSS3的@keyframes用法详解
    phpcms安装与使用
    PDO 数据访问抽象层
    ajax的分页查询
    php 增删改查范例(3)
    php 增删改查范例(2)
    maven部署项目流程(区分环境)
    springboot分环境打包(maven动态选择环境)
    Guava Cache -- MapMaker.makeComputingMap测试
  • 原文地址:https://www.cnblogs.com/huafan/p/13641411.html
Copyright © 2011-2022 走看看