IDs having more than 1 ORG

Forum » Forum / Help » IDs having more than 1 ORG
Started by: mkjjmkjj
On: 1259779184|%e %b %Y, %H:%M %Z|agohover
Number of posts: 6
rss icon RSS: New posts
IDs having more than 1 ORG
mkjjmkjj 1259779184|%e %b %Y, %H:%M %Z|agohover

I'm using the Peoplesoft Query reporting tool (version 8.9) and I can't just type a sql statement. I hope I'm giving you all the information needed:

2 Tables:

table 1

ID SUBJECT CRSE_NUMBER SECTION
1 TEST 500 1
1 PRP 600 3

2 TEST 100 1
2 TE 100 1

3 PRP 200 4
3 BT 500 1
3 SD 200 5

Joined with table 2 on subject

SUBJECT ORG

TEST TEST
TE TEST
PRP PRP
BT BTL
SD SDY

I need to find all IDs that have more then 1 ORG so it would only retrieve:

ID SUBJECT CRSE_NUMBER SECTION
1 TEST 500 1
1 PRP 600 3

3 PRP 3200 4
3 BT 4500 1
3 SD 4200 5

Help is appreciated.

Reply  |  Options
Unfold IDs having more than 1 ORG by mkjjmkjj, 1259779184|%e %b %Y, %H:%M %Z|agohover
Re: IDs having more than 1 ORG
PrajPraj 1259886666|%e %b %Y, %H:%M %Z|agohover

There's generally two ways to approach this depending on your background:

  1. Think about the scenario in PSQuery and build it in PSQuery
  2. Think about the scenario in SQL, write and test in SQL and then replicate the logic in PSQuery

I prefer the second approach, as I think it lets you be more expressive and utilise the full power of SQL. Then the challange isn't how do you write the query, it becomes how to do you make PSQuery generate the SQL…

Since I don't have the table/view names, I figure the SQL might look something like this?

select A.ID, A.SUBJECT, A.CRSE_NUMBER, A.SECTION, count(distinct B.ORG)
from TABLE1 A inner join TABLE2 B
on A.SUBJECT = B.SUBJECT
group by A.ID, A.SUBJECT, A.CRSE_NUMBER, A.SECTION
having count(distinct B.ORG) > 1

This joins the two tables together on subject, groups by the fields in TABLE1 and then counts the number distinct ORGs in TABLE2 and only returns cases where there is more than 1 distinct ORG.

To do this PSQuery:

  • Add your two tables in the query, standard join on the common fields (e.g. INSTITUTION, SUBJECT)
  • Select the appropriate fields you need from TABLE1
  • Click on Having, and add the having criteria. You will need to add an expression which is count(distinct B.ACAD_ORG) as an aggregate function so that it generates the correct having SQL. I don't think you can get around this without using an expression. Make it greater than or equal to a constant value of 1.
  • Go to expressions and add your expression as a field as well (to list the distinct ORGs)

Here's a screenshot of the expression I think you would need:

ids-more-than-1-org-expression.png

Here's a screenshot of the having crteria properties you would then use:

ids-more-than-1-org-having-criteria.png

Note this took a bit of fiddling to get right in PSQuery, hopefully I have the steps right, please reply if you have any problems.

Last edited on 1259886873|%e %b %Y, %H:%M %Z|agohover By Praj + Show more
Reply  |  Options
Unfold Re: IDs having more than 1 ORG by PrajPraj, 1259886666|%e %b %Y, %H:%M %Z|agohover
Re: IDs having more than 1 ORG
mkjj (guest) 1264441322|%e %b %Y, %H:%M %Z|agohover

Sorry it took so long to reply back about the query. The query isn't returning any ids and I know there are ids that have subject\crse number\section with different acad orgs. Any help is appreciated.

Reply  |  Options
Unfold Re: IDs having more than 1 ORG by mkjj (guest), 1264441322|%e %b %Y, %H:%M %Z|agohover
Re: IDs having more than 1 ORG
PrajPraj 1264719007|%e %b %Y, %H:%M %Z|agohover

Would you be able to post the SQL from your PSQuery that you are running please?

Reply  |  Options
Unfold Re: IDs having more than 1 ORG by PrajPraj, 1264719007|%e %b %Y, %H:%M %Z|agohover
Re: IDs having more than 1 ORG
mkjj (guest) 1265749408|%e %b %Y, %H:%M %Z|agohover

Here is the SQL that is automatically created. There is an effective date in table 2 that I forgot and it automatically puts in the statement (AND B.EFFDT=……).

SELECT DISTINCT A.TERM, A.ID, A.SUBJECT, A.CRSE_NUMBER, A.SECTION, count(distinct B.ORG)
FROM CLASS_VW A, SUBJECT B
WHERE B.SUBJECT = A.SUBJECT
AND B.EFFDT =
(SELECT MAX(B_ED.EFFDT) FROM SUBJECT B_ED
WHERE B.SUBJECT = B_ED.SUBJECT
AND B_ED.EFFDT <= SYSDATE)
AND A.TERM = :1
GROUP BY A.ID, A.TERM, A.SUBJECT, A.CRSE_NUMBER, A.SECTION
HAVING count(distinct B.ORG) > 1

Thanks for you help!

Reply  |  Options
Unfold Re: IDs having more than 1 ORG by mkjj (guest), 1265749408|%e %b %Y, %H:%M %Z|agohover
Re: IDs having more than 1 ORG
PrajPraj 1266795308|%e %b %Y, %H:%M %Z|agohover

It could be the automatic effective date join that's causing the issue? Have tried taking that out of query to see if you get any results?

Reply  |  Options
Unfold Re: IDs having more than 1 ORG by PrajPraj, 1266795308|%e %b %Y, %H:%M %Z|agohover
New Post
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License