Oracle cookie remark

//利用decode实现枚举值到枚举名称的一个转换:
select count(t.id) as amount,
       decode(t.CAPITAL_TYPE,
              1,
              '有帐设备',
              2,
              '买断设备',
              3,
              '帐消库存',
              4,
              '净值为零') as name
  from Mach_Basic_Info t
 where t.mach_state in (1, 2)
 group by t.CAPITAL_TYPE
 order by amount desc
//对具有id-parent_id结构的字典表进行一个第一级别的关联汇总:
select t1.parent_id, t1.amount, t2.type_name
  from (select d.parent_id, count(t.id) as amount
          from Mach_Basic_Info t, Mach_Type_dict d
         where t.mach_type_id = d.id
           and t.mach_state in (1, 2)
         group by d.parent_id) t1,
       Mach_Type_dict t2
 where t1.parent_id = t2.id
 order by amount desc
//对具有id-parent_id,inner_code(内部层次编码,开发可见),outer_code(外部用户编码,用户可见)结构的字典表进行一个关联查询:
 select *
   From (select m.MANAGE_DEPT_ID,
                t.inner_code,
                m.original_value,
                m.net_value
           from mach_basic_info m, mach_type_dict t
          Where m.mach_state in (1, 2)
            and m.mach_type_id = t.id) t,
        mach_type_dict t1
  Where t1.inner_code = substr(t.inner_code, 1, 4)
    And t1.parent_id is null 

//按2000年的12个月份对数量,原值,净值进行汇总,以万元计

select substr(to_char(t.Acquisition_Date, 'yyyy-mm-dd'), 6, 2),
       count(t.id),
       round(sum(t.original_value) / 10000) as originalVal,
       round(sum(t.net_value) /10000) as netVal
  from mach_basic_info t
 where substr(to_char(t.Acquisition_Date, 'yyyy-mm-dd'), 1, 4) = '2000'
   and t.owner_dept_id = 1
 group by substr(to_char(t.Acquisition_Date, 'yyyy-mm-dd'), 6, 2)
 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值