case函数 (适合区间,>,<判断)
   case when 判断表达式 then
        when 判断表达式 then
        .....
   end
 
  select deptno,count(*) total,
   sum(case when sal>=2000 then 1
       end) great,
   sum(case when sal<2000 then 1
       end) least
  from emp
  where deptno is not null
  group by deptno;
 
//统计部门中男人数和女人数
 create table j20(
  id number(7),
  name varchar(20),
  sex char(1), --'M'或'F'
  deptno number(7));
 
 select deptno,
        sum(decode(sex,'M',1,0)) as male,
        sum(decode(sex,'F',1,0)) as female
 from j20
 group by deptno;
 
 select deptno,
        sum(case when sex='M' then 1
            else 0 end) as male,
        sum(case when sex='F' then 1
            else 0 end) as female
 from j20
 group by deptno;
 //基于EMP表查询部门编号,工资1000以内人数,
 1000-2000人数,2000以上人数
 select deptno,
    sum(case when sal<1000 then 1
             else 0
        end) "1000以内",
    sum(case when sal>=1000 and sal<2000 then 1
             else 0
        end) "1000-2000",
    sum(case when sal>=2000 then 1
             else 0
        end) "2000以上"
 from emp
 group by deptno;
 
 //查询调薪结果,规则:MANAGER涨10%,CLERK涨20%,
  其他人涨5%
 select empno,ename,job,sal,
        decode(job,'MANAGER',sal*1.1,
                   'CLERK',sal*1.2,
                   sal*1.05) "加薪之后"
 from emp;

高级函数-case的更多相关文章

  1. MySQL高级函数case的使用技巧----与sum结合实现分段统计

    case 函数 CASE WHEN condition1 THEN result1 WHEN condition2 THEN result2 ... WHEN conditionN THEN resu ...

  2. javascript高级函数

    高级函数 安全的类型检测 js内置的类型检测并非完全可靠,typeof操作符难以判断某个值是否为函数 instanceof在多个frame的情况下,会出现问题. 例如:var isArray = va ...

  3. js 高级函数 之示例

    js 高级函数作用域安全构造函数 function Person(name, age)    {        this.name = name;        this.age = age;     ...

  4. 浅谈JS中的高级函数

    在JavaScript中,函数的功能十分强大.它们是第一类对象,也可以作为另一个对象的方法,还可以作为参数传入另一个函数,不仅如此,还能被一个函数返回!可以说,在JS中,函数无处不在,无所不能,堪比孙 ...

  5. php一些高级函数方法

    PHP高级函数 1.call_user_func (http://php.net/manual/zh/function.call-user-func.php) 2.get_class (http:// ...

  6. Python函数式编程(二):常见高级函数

    一个函数的参数中有函数作为参数,这个函数就为高级函数. 下面学习几个常见高级函数. ---------------------------------------------------------- ...

  7. Python函数式编程(一):高级函数

    首先有一个高级函数的知识. 一个函数可以接收另一个函数作为参数,这种函数就称之为高阶函数. def add(x, y, f): return f(x) + f(y) 当我们调用add(-, , abs ...

  8. Day11 Python基础之装饰器(高级函数)(九)

    在python中,装饰器.生成器和迭代器是特别重要的高级函数   https://www.cnblogs.com/yuanchenqi/articles/5830025.html 装饰器 1.如果说装 ...

  9. Oracle特有函数 case when decode exists 分页rownum

    select * from EMP eselect * from dept dselect * from salgrade s--Oracle特有函数 case whenselect case 2 w ...

随机推荐

  1. ie6 bug 收集

    1.IE6中奇数宽高的BUG IE6下查看,变成了right:1px的效果了: IE6还有奇数宽高的bug,解决方案就是将外部相对定位的div宽度改成偶数.高度也是一样的查看源码: CSS代码: #o ...

  2. js/jquery 判断支持touchstart

      if ('ontouchstart' in document.documentElement) { //... }

  3. 串口通讯 ADC0804 数码管

    #include<reg52.h> #include<stdio.h> #include<intrins.h> #define uchar unsigned cha ...

  4. GO语言UDP小笔记

    <pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#0000f ...

  5. reactjs simple text editor

    import React, { Component } from 'react' import PubSub from 'pubsub' import GlobalVars from 'globalV ...

  6. 【iOS开发系列】XIB IBOutlets use strong or weak ?

    有人问.在ARC下,IBOutlets究竟应该定义成strong 还是 weak ?支持这个答案的人最多.答案仅是摘自官方文档的一个片段: From a practical perspective, ...

  7. php之将用户信息写入数据库

    session高级应用将用户信息写入到数据库中 首先建立数据库表 在实验数据库sqldb中建立session表,用于存储数据 在根文件夹下建立须要用到的文件(重点是session,class.php这 ...

  8. tapestry3创建自己定义组件

    两种方法创建自己定义标签: 一.通过AbstractComponent父类渲染,此种方法直接在java类中编写页面脚本.然后输出. 1.编写java类com/ailk/ech/ecop/view/te ...

  9. 每天一个JavaScript实例-tab标签切换

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  10. Swift3.0 闭包整理

    语法表达式 一般形式:{             (parameters) -> returnType in              statements            } 这里的参数 ...