Computing.Net > Forums > Database > Managerial Roll-up

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Managerial Roll-up

Reply to Message Icon

Name: lankrypt0
Date: March 12, 2008 at 10:23:33 Pacific
OS: Linux
CPU/Ram: N/A
Product: N/A
Comment:

I am using an ORACLE databse and having a real problem figuring out how to do a "roll-up" for manager reporting. I do not have access to write to another database, and I only have read access to the current one.
So I have a table with the following fields:
EMAIL_ADR, PERSON_ID, SUPERVISOR_ID
Person_ID is uniqie for each user, and when they are the supervisor for a user, their PERSON_ID shows up in that persons SUPERVISOR_ID field.

For example, lets say I have the following table:
EMAIL_ADR, PERSON_ID, SUPERVISOR_ID
bob@email.com, 2, 1
jim@email.com, 3, 1
sue@email.com, 4, 2
jay@email.com, 5, 3
mike@email.com, 6, 4
sean@email.com, 7, 5
lee@email.com, 8, 6
fred@email.com, 9, 7

What I am attempting to do is get the EMAIL_ADR for every user who ultimately rolls up to PERSON_ID 1, which would be everyone on the list. I tried the following:
select EMAIL_ADR from TABLE where PERSON_ID in (
select PERSON_ID from TABLE where SUPERVISOR_ID in (
select PERSON_ID from TABLE where SUPERVISOR_ID in (
select PERSON_ID from TABLE where SUPERVISOR_ID in (
select PERSON_ID from TABLE where SUPERVISOR_ID in (
select PERSON_ID from TABLE where SUPERVISOR_ID in ('1');

Any help would be greatly appreciated. I am at a complete loss here.




Sponsored Link
Ads by Google

Response Number 1
Name: nev1
Date: March 12, 2008 at 11:05:16 Pacific
Reply:

Try the following:

SELECT EMAIL_ADR
FROM TABLE
CONNECT BY SUPERVISOR_ID = PERSON_ID


0

Response Number 2
Name: lankrypt0
Date: March 13, 2008 at 06:23:42 Pacific
Reply:

That is the right track I think, but unfortunately in my live data we have some circular references. In reality we have Bob reporting to Sue, but Sue is also listed as reporting to Bob. In doing some google searching, it seems version 10g has a way of overcoming that, which is what I am looking into now. Though if anyone has any suggestesions, I'd be happy to hear them.


0

Response Number 3
Name: lankrypt0
Date: March 13, 2008 at 10:10:02 Pacific
Reply:

For those interested, I found the solution to this problem:
select email_adr
from SP_IDENTITY_MASTER
start with person_id = '1'
connect by nocycle prior person_ID = supervisor_id;


0

Response Number 4
Name: Jennifer SUMN
Date: March 19, 2008 at 04:57:47 Pacific
Reply:

Isn't that what nev1 suggested?

Life's more painless for the brainless.


0

Response Number 5
Name: lankrypt0
Date: March 19, 2008 at 12:39:03 Pacific
Reply:

Jennifer,
Umm, no. It was close, and pointed me in the right directeion. I ran into a problem with looping, which is why I needed the "connect by nocycle prior" and not just "connect by".


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Database Forum Home


Sponsored links

Ads by Google


Results for: Managerial Roll-up

calculation across hierarchies www.computing.net/answers/dbase/calculation-across-hierarchies/544.html

auto back up in M. access www.computing.net/answers/dbase/auto-back-up-in-m-access/181.html

setting up database www.computing.net/answers/dbase/setting-up-database/278.html