ORACLE查詢當前資產狀態,和另一個資料庫聯查,(查詢重複資料中第一條),子查詢作為欄位查詢

來源:互聯網
上載者:User

標籤:

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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.