//利用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)