3

以下の2つの表をまとめて、日報にまとめる必要があります。

表1:Resource_Created

FirstNameLastNameObjDateリソースログイン

TestDemo1        TestDemo1       5-Oct-12         AD         TESTDEMO1

表2:Resource_Deleted

FirstNameLastNameObjDateリソースログイン

TestDemo4        TestDemo4       5-Oct-12         AD         TESTDEMO4

TestDemo5        TestDemo5       5-Oct-12         AD         TESTDEMO5

TestDemo6        TestDemo6       5-Oct-12         AD         TESTDEMO6

TestDemo4        TestDemo4       5-Oct-12         Bio        TESTDEMO4

TestDemo4        TestDemo4       5-Oct-12         VPN        TESTDEMO4

TestDemo5        TestDemo5       5-Oct-12         VPN        TESTDEMO5

TestDemo6        TestDemo6       5-Oct-12         VPN          TESTDEMO6

私は2つのクエリを個別に書きました

クエリ1:

select distinct Resource as Resource, 
       count (distinct Login) as CountRes 
from Resource_Created 
where ObjDate between '4-Oct-12' and '6-Oct-12' 
group by Resource ;

結果:

リソースCountRes

 AD        1

クエリ2:

select distinct Resource as Resource, 
       count (distinct Login) as CountRes 
from Resource_Deleted 
where ObjDate between '4-Oct-12' and '6-Oct-12' 
group by Resource ;

結果

リソースCountRes

AD          3

VPN         3

Bio         1

これらの2つのクエリを組み合わせて、1つのテーブルにこれらの値を表示させることができます。

select COALESCE (Resource_Created.Resource, Resource_Deleted.Resource) as Resource , 
 count (distinct Resource_Created.usrlogin) as aobj, 
 count (distinct Resource_Deleted.usrlogin) as bobj
FROM target_failed  FULL OUTER JOIN target_resource  
 on Resource_Created.Resource = Resource_Deleted.Resource 
where
 Resource_Created.ObjDate between '04-OCT-2012' and '06-OCT-2012' and 
 Resource_Deleted.ObjDate between '04-OCT-2012' and '06-OCT-2012'
group by COALESCE(Resource_Created.Resource, Resource_Deleted.Resource);

私の結果は

**Resource       aobj         bobj**

   AD         1                3

期待される結果

リソースaobjbobj

 AD             1          3

VPN           Null         3

Bio           Null         1

誰かが私が問題を解決するのを手伝ってくれませんか。私は基本的なSQLクエリを作成するOO開発者です。よろしくお願いします。

4

1 に答える 1

2

単にsubsqlonfromステートメントを使用します

select 
  ResourceI as rs, sum (CreatedLogin) as CountCreated,
 sum (DeletedLogin) as CountDeleted
from 
(select 
 ObjDate,
 Resource ,
 1 as DeletedLogin,
 0 as CreatedLogin 
 from  Resource_Deleted
 union all
 select ObjDate,
 Resource ,
 0 as DeletedLogin,
 1 as CreatedLogin  
 from  Resource_Created
)  TABLE_ALL
where ObjDate between TO_DATE('4-Oct-12') and TO_DATE('6-Oct-12')
group by Resource
于 2012-10-14T10:09:59.093 に答える