SELECT BUSINESS_UNIT , ASSET_ID , BOOK , CATEGORY , SUM(QUANTITY) , SUM(COST) , FROM_CUR FROM PS_COST_BAL_VW9 WHERE NOT EXISTS (SELECT 'X' FROM PS_ASSET_ACQ_DET WHERE PS_ASSET_ACQ_DET.BUSINESS_UNIT = PS_COST_BAL_VW9.BUSINESS_UNIT AND PS_ASSET_ACQ_DET.ASSET_ID=PS_COST_BAL_VW9.ASSET_ID) GROUP BY BUSINESS_UNIT , ASSET_ID , BOOK , CATEGORY , FROM_CUR UNION SELECT A.BUSINESS_UNIT , A.ASSET_ID , A.BOOK , B.CATEGORY , SUM(A.QUANTITY) , SUM(A.COST) , A.FROM_CUR FROM PS_COST_BAL_VW9 A , ( SELECT DISTINCT C.BUSINESS_UNIT ,C.ASSET_ID ,C.CATEGORY FROM PS_ASSET_ACQ_DET C) B WHERE A.BUSINESS_UNIT = B.BUSINESS_UNIT AND A.ASSET_ID=B.ASSET_ID GROUP BY A.BUSINESS_UNIT , A.ASSET_ID , A.BOOK , B.CATEGORY , A.FROM_CUR
|