DECODE()函数

select count(distinct case substr(t.eqcode,1,1) when '0' then t.eqcode end) 零类,
       count(distinct case substr(t.eqcode,1,1) when '1' then t.eqcode end) 一类,
       count(distinct case substr(t.eqcode,1,1) when '2' then t.eqcode end) 二类,
       count(distinct case substr(t.eqcode,1,1) when '3' then t.eqcode end) 三类,
       count(distinct case substr(t.eqcode,1,1) when '4' then t.eqcode end) 四类,
       count(distinct case substr(t.eqcode,1,1) when '5' then t.eqcode end) 五类,
       count(distinct case substr(t.eqcode,1,1) when '6' then t.eqcode end) 六类,
       count(distinct case substr(t.eqcode,1,1) when '7' then t.eqcode end) 七类,
       count(distinct case substr(t.eqcode,1,1) when '8' then t.eqcode end) 八类,
       count(distinct case substr(t.eqcode,1,1) when '9' then t.eqcode end) 九类,
       count(distinct EQCODE) 合计,
 decode(t.eqdyna,2,'调入',3,'新购',4,'自制',5,'调出',6,'报废',7,'封存',8,'启封',9,'移装',10,'未定义',11,'待报废')
       from gzequipment t
       group by t.eqdyna

t.eqcode 以0开头的是零类
t.eqcode 以1开头的是一类
t.eqcode 以2开头的是二类
t.eqcode 以3开头的是三类
t.eqcode 以4开头的是四类
t.eqcode 以5开头的是五类
t.eqcode 以6开头的是六类
t.eqcode 以7开头的是七类
t.eqcode 以8开头的是八类
t.eqcode 以9开头的是九类
t.eqdyna 的值是2 则为 调入
t.eqdyna 的值是3 则为 新购
t.eqdyna 的值是4 则为 自制
t.eqdyna 的值是5 则为 调出
t.eqdyna 的值是6 则为 报废
t.eqdyna 的值是7 则为 封存
t.eqdyna 的值是8 则为 启封
t.eqdyna 的值是9 则为 移出
t.eqdyna 的值是11 则为 未定义
t.eqdyna 的值是12 则为 待报废

这个查询语句的作用是:
     根据t.eqdyna的取值的不同 统计所有t.eqcode以0开头、以1开头、以2开头、以3开头、
以4开头、以5开头、以6开头、以7开头、以8开头、以9开头 设备数量
     这里会遍历.teqdyna


查询结果:
                   零类   一类   二类   三类   四类   五类   六类   七类   八类   九类 
            调入
            新购
            自制
            调出
            报废
            封存
            启封
            移出
           未定义
           待报废
           

 

 


decode(条件,值1,翻译值1,值2,翻译值2,...值n,翻译值n,缺省值)

该函数的含义如下:
IF 条件=值1 THEN
    RETURN(翻译值1)
ELSIF 条件=值2 THEN
    RETURN(翻译值2)
    ......
ELSIF 条件=值n THEN
    RETURN(翻译值n)

ELSE
    RETURN(缺省值)
END IF


substr(t.eqcode,1,1)
该函数的含义如下:
从t.eqcode的第1位取一个值
case substr(t.eqcode,1,1) when '0' then t.eqcode end
如果t.eqcode的第一位的第一个的值是0则t.eqcode结束

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值