标签:
背景:ORACLE查询当前资产状态,包含资产信息(表1),资产维修状态(表2),资产报废状态(表3)
如下:
资产信息:
资产维修:
资产报废:
资产申请完了以后可以申请当前资产的维修和报废,其中维修有两个流程,一个是申请维修,然后维修。对应的都需要启动相应的流程去申请维修或者报废
流程表如下:
查询当前所有的资产以及对应的资产状态(维修状态,报废状态):sql语句如下:
select t.ASSET_ID as assetId,
t.ASSET_NAME as assetName,
t.ASSET_SORT as assetSort,
t.ASSET_MODEL as assetModel,
t.BIRTH_DATE as birthDate,
t.INTERNATIONAL_NUMBER as internationalNumber,
t.MANUFACTURER as manufacturer,
t.PURCHASE_DATE as purchaseDate,
t.NET_SALVAGE as netSalvage,
t.EXPECTED_YEAR as expectedYear,
t.NET_VALUE as netValue,
t.ORIGINAL_VALUE as originalValue,
t.DEPRECIATION_METHOD as depreciationMethod,
t.SERVICE_CONDITION as serviceCondition,
t.STOREMAN as storeMan,
t.REMARK as remark,
t.ADD_TYPE as addType,
t.PROCESSINSTANCEID as processinstanceId,
t.CUSTODY_DEPT as custodyDept,
t.USED_YEAR as usedYear,
t.ID as Id,
m.status as clearStatus,
-- nn.status as maintainStatus,
(select a.status
from (select a.asset_id, b.status
from asset_maintain a
join workflow.workflow_execution b
on b.processinstanceid = a.processinstanceid
order by b.create_time desc) a
where a.asset_id = t.asset_id
and rownum = 1) as maintainStatus
from ASSET_INFO t
left join (select *
from ASSET_CLEAR c
join workflow.workflow_execution n
on c.processinstanceid = n.processinstanceid) m
on t.asset_id = m.asset_id
重点是这里:
领悟:子查询可以作为业务字段使用,同时可以根据当前主查询的表进行相关联,取出自己想要的数据
ORACLE查询当前资产状态,和另一个数据库联查,(查询重复数据中第一条),子查询作为字段查询
标签:
原文地址:http://www.cnblogs.com/zrui-xyu/p/4577251.html