標籤:
背景: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查詢當前資產狀態,和另一個資料庫聯查,(查詢重複資料中第一條),子查詢作為欄位查詢