ORACLE的CASE WHEN表达式

  1. CASE WHEN语句的一般用法,通过条件判断返回对应的值。
    例:查询若部门号为 10, 则打印其工资的 1.1 倍, 20 号部门, 则打印其工资的 1.2 倍, 30 号部门打印其工资的 1.3 倍数
 select last_name, department_id, salary, 
    case department_id when 10 then 1.10*salary 
    when 20 then 1.15*salary 
    when 30 then 1.20*salary 
    else salary 
    end "revised_salary " 
    from employees
  1. CASE WHEN语句还可以用于统计
    例:统计列印各科成绩,各分数段人数:课程ID,课程名称,[100-85],[85-70],[70-60],[ <60]
select b.cno,cname,
sum(case  when score between 85 and 100 then 1 else 0 end) "[100-85]",
sum(case  when score between 70 and 85 then 1 else 0 end) "[85-70]",
sum(case  when score between 60 and 70 then 1 else 0 end) "[70-60]",
sum(case  when score <60 then 1 else 0 end) "[<60]"
from course a,sc b where a.cno = b.cno group by b.cno,cname
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值