Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

Oracle SQL query: Finding the number of counts of similar objects between parent proj

$
0
0
I am stuck on this part.

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.

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

Also, edit this post, as I am not aware on how to do this.

Database in use is Oracle.

Kindly let me know if further information is required.

Thanks a lot for your time and help.

Viewing all articles
Browse latest Browse all 13329

Trending Articles