0

I am stuck on this part. Also, this is in continuation of, as I don't want the members to get confused. How to find the child project of a parent project which is passed in the 'WHERE' clause and also, to find the duplicate objects I have prepared a query:

SELECT A.projectName as PARENT,
(select COUNT(*) from PSPROJECTITEM WHERE PROJECTNAME = A.PROJECTNAME) parentprojecount, 
B.ProjectName as CHILD, 
(select COUNT(*) from PSPROJECTITEM WHERE PROJECTNAME = B.PROJECTNAME) CHILDPROJECT,
(select count(*) from PSPROJECTITEM A
LEFT OUTER join PSPROJECTITEM B
 on b.objecttype = a.objecttype 
   AND b.objectid1 =a.objectid1 
   AND b.objectvalue1 = a.objectvalue1 
   AND b.objectid2 = a.objectid2 
   AND b.objectvalue2 = a.objectvalue2 
   AND b.objectid3 = a.objectid3 
   AND b.objectvalue3 = a.objectvalue3 
   AND b.objectid4 = a.objectid4 
   AND B.OBJECTVALUE4 = A.OBJECTVALUE4
   AND  A.PROJECTNAME = 'AAAA_JOB_KJ'
   WHERE A.PROJECTNAME <> B.PROJECTNAME 
   )
 AS SIMILAROBJECTCOUNTPARENTAND CHILD
   from psprojectitem a  INNER JOIN psProjectItem  B 
   ON a.objecttype = b.objecttype 
   AND a.objectid1 =b.objectid1 
   AND a.objectvalue1 = b.objectvalue1 
   AND a.objectid2 = b.objectid2 
   AND a.objectvalue2 = b.objectvalue2 
   AND a.objectid3 = b.objectid3 
   AND a.objectvalue3 = b.objectvalue3 
   AND a.objectid4 = b.objectid4 
   AND a.objectvalue4 = b.objectvalue4
WHERE A.projectname in 
(SELECT ProjectName from psProjectDefn WHERE lastupdoprid <> 'PPLSOFT') 
AND a.projectname <> B.projectName
and A.PROJECTNAME = 'AAAA_JOB_KJ'
group by A.PROJECTNAME,B.PROJECTNAME
ORDER BY B.PROJECTNAME

I am stuck on the part where i need to find the count of similar objects which are similar between the parent and child.

For eg, here i am passing 'AAAA_JOB_KJ' in the where clause, which is my parent project. The query retrieves the parent project name, count of parent project name, child project of this project name, count of the child project. All this is find.

My real problem is that query which I have written is not fetching the correct count for the similar objects which are between the parent and the child.

I will post the details below:

The column names of PSPROJECTITEM:

 PROJECTNAME    OBJECTTYPE  OBJECTID1   OBJECTVALUE1    OBJECTID2   OBJECTVALUE2    OBJECTID3   OBJECTVALUE3    OBJECTID4   OBJECTVALUE4

The desired output:

ParentProjectName  ParentProjectCount ChildProject  Child Count Similar Object Count

This is the header of the file, can be ignored. This part is the output:

 AAAA_JOB_KJ                 199     AZ_AUTOFILL_SP1    11     3

The output returned by my query:

AAAA_JOB_KJ                      199        AZ_AUTOFILL_SP1     11  945

The rest of the data is fine, except for the similar object count.

The objectcount have to be checked between the AAAA_JOB_KJ and AZ_AUTOFILL_SP1, and the count of the similar objects amongst them have to be retrieved, I am stuck on this part.

What I have tried here is that I have tried to map the parent object in the left outer join, so that the object present in table A and in table B gets retrieved. This is how I am trying to fetch the duplicate rows.

The query result is as follows:

SELECT * FROM PSPROJECTITEM WHERE projectname = 'AAAA_JOB_KJ';

One such row in this query is:

AAAA_JOB_KJ 8   1   JOB 2   EMPL_RCD    12  SavePostChange  0

Similarly:

SELECT * FROM PSPROJECTITEM WHERE PROJECTNAME = 'AZ_AUTOFILL_SP1';

One such row is:

AZ_AUTOFILL_SP1 8   1   JOB 2   EMPL_RCD    12  SavePostChange  0

Hence, it is clear that the one row is common amongst AAAA_JOB_KJ and AZ_AUTOFILL_SP1, which both have parent and child relationship. So, the count of similar objects amongst them is 1, though, it is more than one for these two table, there are total of 3 similar rows with same object id between these two table.

I want a query which will count the number of similar objects.

Please don't hesitate in calling me wrong, I am open to all suggestions.

Database in use is Oracle.

Kindly let me know if further information is required.

Thanks a lot for your time and help.

4

1 回答 1

0

The problem is solved:

SELECT A.projectName as PARENT,
(select COUNT(*) from PSPROJECTITEM WHERE PROJECTNAME = A.PROJECTNAME) parentprojecount, 
B.ProjectName as CHILD, 
(select COUNT(*) from PSPROJECTITEM WHERE PROJECTNAME = B.PROJECTNAME) CHILDPROJECT,
(select COUNT(*) from PSPROJECTITEM 
where PROJECTNAME = B.projectname

AND  objecttype IN ( SELECT c.OBJECTTYPE FROM PSPROJECTITEM c WHERE c.PROJECTNAME = 'AAAA_JOB_KJ')
   AND objectid1 IN ( SELECT c.OBJECTID1 FROM PSPROJECTITEM c WHERE c.PROJECTNAME = 'AAAA_JOB_KJ')
   AND objectvalue1 in ( SELECT c.objectvalue1 FROM PSPROJECTITEM c WHERE c.PROJECTNAME = 'AAAA_JOB_KJ')
   AND objectid2 in ( SELECT c.objectid2 FROM PSPROJECTITEM c WHERE c.PROJECTNAME = 'AAAA_JOB_KJ')
   and objectvalue2 in ( SELECT c.objectvalue2 FROM PSPROJECTITEM c WHERE c.PROJECTNAME = 'AAAA_JOB_KJ')
   AND objectid3 in ( SELECT c.objectid3 FROM PSPROJECTITEM c WHERE c.PROJECTNAME = 'AAAA_JOB_KJ')
   AND objectvalue3 in ( SELECT c.objectvalue3 FROM PSPROJECTITEM c WHERE c.PROJECTNAME = 'AAAA_JOB_KJ')
   AND objectid4 in ( SELECT c.objectid4 FROM PSPROJECTITEM c WHERE c.PROJECTNAME = 'AAAA_JOB_KJ')
   AND OBJECTVALUE4  in ( SELECT c.OBJECTVALUE4 FROM PSPROJECTITEM c WHERE c.PROJECTNAME = 'AAAA_JOB_KJ')
   )
 AS SIMILARCOUNT
   from psprojectitem a  INNER JOIN psProjectItem  B 
   ON a.objecttype = b.objecttype 
   AND a.objectid1 =b.objectid1 
   AND a.objectvalue1 = b.objectvalue1 
   AND a.objectid2 = b.objectid2 
   AND a.objectvalue2 = b.objectvalue2 
   AND a.objectid3 = b.objectid3 
   AND a.objectvalue3 = b.objectvalue3 
   AND a.objectid4 = b.objectid4 
   AND a.objectvalue4 = b.objectvalue4
WHERE A.projectname in 
(SELECT ProjectName from psProjectDefn WHERE lastupdoprid <> 'PPLSOFT') 
AND a.projectname <> B.projectName
and A.PROJECTNAME = 'AAAA_JOB_KJ'
group by A.PROJECTNAME,B.PROJECTNAME
ORDER BY B.PROJECTNAME

which gives the following output:

AAAA_JOB_KJ 199 ALTAUDIT    58201   1
AAAA_JOB_KJ 199 AZ_ADDL_PAY_FIX 3   1
AAAA_JOB_KJ 199 AZ_ADPNBR   6   4
AAAA_JOB_KJ 199 AZ_ADP_NUMBER   2   2
AAAA_JOB_KJ 199 AZ_AMZR_6   3   2
AAAA_JOB_KJ 199 AZ_AMZR_NM  405 8
AAAA_JOB_KJ 199 AZ_ARCH_QUERY_SECURITY  8   1
AAAA_JOB_KJ 199 AZ_ATMT_JIRA_5797   1   1
AAAA_JOB_KJ 199 AZ_AUDIT_RECORDS    53  1
AAAA_JOB_KJ 199 AZ_AUTOFILL_SP1 11  5

Also, there were many modifications on the table, the concerned person told me this yesterday.

于 2013-06-18T07:23:55.530 回答