SQL that may be impossible to write

I am currently using a 10.2.0.4 version Oracle Database.
I have a table that contains all of the employees with a REPORTS_TO column so you can tell which employee reports to whom. The data looks something like this:
POSITION_NBR EMP_NAME JOB_TITLE REPORTS_TO
1122 Boss, Ima Owner
5421 Mann, James Manager 1122
5621 Black, Mary Manager 1122
2201 Clark, Michael Supervisor 5421
6620 Reed, Roland Supervisor 5621
6890 Jackson, William Supervisor 5421
7220 Hansome, Jack Supervisor 5421
3342 Terry, Cherry Desktop 2201
6902 Butter, Pat Admin 2201
7365 Gonzales, Slyvia Admin 6890
7369 Knapp, Jason Sales 6890
7370 Fedric, Justin Sales 6890
7401 Blakeney, Albert Sales 6890
7422 Mora, Phillip Admin 7220
9880 Herrera, Milton Driver 7220
9882 Aguire, Fred Driver 7220
9900 Armijo, Randall Laborer 6620
9960 Watkins, Jack Laborer 6620
By looking at the data you can see that POSITION_NBR 1122 is the owner of the place and doesn't report to anyone. If you look down the REPORTS_TO column for 1122, you can see that there are two Manager's who report to the Owner because the 1122 is his position number.
The data above I just made up. The real data probably has 8 or 10 levels with hundreds of employees. I want to write an SQL where I can say show me all of the employee's that belong to a specific POSITION_NBR, no matter what the level and get back all of that person's employees. So, if I wanted to see 5621s employee's I would like to get back POSITION_NBRs: 6620, 9900, and 9960, because I want to include the subordinates. If you look at the data 6620 is the only person reporting to 5621, but 9900 and 9960 report to position 6620 so I want to include them.
I am really poor with Analytical Functions, but from what I see I cannot use them any way. I can write a correlated sub-query, but since I'm not sure how many levels I want, I'm not sure how I could write it to get back all of the appropriate people in one column anyway. I can do it with PL/SQL, but would really like an SQL Statement that I could use.
If I wanted to see all of William Jackson's employee's I would like to see POSITION_NBRs 7365, 7369, 7370, and 7401 come back. If I wanted to see all of Michael Clark's employees I would like to see POSITION_NBRs 3342 and 6902 come back. If I wanted to see Ima Boss's employee's I would like to see all of the POSITION_NBRs returned.
Is this possible to do with SQL or should I just stick with PL/SQL?
Any help is appreciated.
The scripts below can be used to create the example data:
create table example_table
(position_nbr number,
emp_name varchar2(40),
job_title varchar2(20),
reports_to number);
insert into example_table values(1122,'Boss, Ima','Owner','');
insert into example_table values(5421,'Mann, James','Manager','1122');
insert into example_table values(5621,'Black, Mary','Manager','1122');
insert into example_table values(2201,'Clark, Michael','Supervisor','5421');
insert into example_table values(6620,'Reed, Roland','Supervisor','5621');
insert into example_table values(6890,'Jackson, William','Supervisor','5421');
insert into example_table values(7220,'Hansome, Jack','Supervisor','5421');
insert into example_table values(3342,'Terry, Cherry','Desktop','2201');
insert into example_table values(6902,'Butter, Pat','Admin','2201');
insert into example_table values(7365,'Gonzales, Slyvia','Admin','6890');
insert into example_table values(7369,'Knapp, Jason','Sales','6890');
insert into example_table values(7370,'Fedric, Justin','Sales','6890');
insert into example_table values(7401,'Blakeney, Albert','Sales','6890');
insert into example_table values(7422,'Mora, Phillip','Admin','7220');
insert into example_table values(9880,'Herrera, Milton','Driver','7220');
insert into example_table values(9882,'Aguire, Fred','Driver','7220');
insert into example_table values(9900,'Armijo, Randall','Laborer','6620');
insert into example_table values(9960,'Watkins, Jack','Laborer','6620');
commit;
Thanks - mike

Thanks for posting the sample data.
From next time if you could format your post it will be much appreciated. Also spend some time reading the oracle manual. It's all documented there.
select * from example_table
start with position_nbr = 6890
connect by prior position_nbr = reports_to;Link for hierarchical queries
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries003.htm#sthref3132
http://tahiti.oracle.com
Regards
Raj

Similar Messages

  • My screen is oversensitive and letters and numbers jump onto the screen when my finger gets close so that it is impossible to write what I want. I tried turning on and off the phone but still the same when I turn back on. Any help or advice appreciated

    My screen is oversensitive and letters and numbers jump onto the screen as my finger gets close. help

    You need to re install OSX. If you have the dmg file downloaded via torrentz this is how you can create a bootable external HD or Flash drive (8 GB+)
    https://discussions.apple.com/message/23957654#23957654
    Peace
    Harry

  • I cannot update from OS 10.9.4 to 10.9.5. I get a message saying: File couldn't be installed error (513). I have configured my OS so that I have read and write permission followed by system with read and writ permission. Can someone help me? Thanks.

    I cannot update from OS X 10.9.4 t0 10.9.5> Whenever I try I get the following message: File couldn't be installed error (513) and something about not having the proper permission.  Under the Macintosh HD sharing and permissions settings I have customized the settings so that (Me) has read and write permission followed by the system with read and write permission, wheel and everyone have Read permissions.
    I have no problems updating apps such as Adobe CC or iTunes but cannot update the operating system, can someone help me? Thanks.

    1. Restart the computer in safe mode. Certain caches maintained by the system will be rebuilt.
    Safe mode is much slower to start up than normal. The next normal startup may also be somewhat slow.
    When the login screen appears, restart as usual (not in safe mode) and test. There's no need to log in while in safe mode.
    Note: If FileVault is enabled, or if a firmware password is set, or if the startup volume is a software RAID, you can’t start in safe mode. In that case, go to Step 2.
    If there's no change after taking this step, continue.
    2. Back up all data before proceeding.
    Triple-click anywhere in the line below on this page to select it:
    /var/folders
    Right-click or control-click the highlighted line and select
              Services ▹ Reveal in Finder (or just Reveal)
    from the contextual menu.* A folder should open with an item named "folders" selected. Move the selected item to the Trash. You may be prompted for your administrator login password. Restart the computer and empty the Trash.
    *If you don't see the contextual menu item, copy the selected text to the Clipboard by pressing the key combination  command-C. In the Finder, select
              Go ▹ Go to Folder...
    from the menu bar and paste into the box that opens by pressing command-V. You won't see what you pasted because a line break is included. Press return.

  • How do you display the SQL that BEx uses?

    All,
    I would like to display the SQL that is submitted to BEx.  I understand you can perform a SQL Trace (ST05), but I want to see the SQL before is submitted to BEx.  Can anyone help me.
    Thanks.

    As Allison mentions - use RSRT, choosing Execute + Debug.
    From there you will see an option, Display SQL Query, which may be what you want, it displays the SAP's Open SQL, but what you might relate better to is the Display  Run Schedule, which will show the SQl as translated to the target DB environment and the Explain (execution) Plan.
    Just as an FYI, ST04 is also useful for seeing the SQL and execution plans of a query that has already run. Check it out if you are not familiar with it.

  • I have files that may have been created in various versions of Illustrator. We need to be able to open them, but all we have is CS6 suite. I have called and been told that "technicians at adobe" could perform a paid service to find out what the files were

    I have files that may have been created in various versions of Illustrator. We need to be able to open them, but all we have is CS6 suite. I have called and been told that "technicians at adobe" could perform a paid service to find out what the files were created in and get them to be useable in InDesign 6, but I'd need an email address that was registered to our software to give the help desk person. After finding the correct email address, different adobe help number people told me to come here to ask as there is no phone support. Can anyone get me to an adobe technician that can provide a price quote for finding out what created these files and for getting them converted? Thanks.

    Sorry, I understood you to say you had the whole CS6 suite, which includes Illustrator.
    As far as finding out what the files are, sometimes you can look at them in a text editor to figure this out. See below; the, Creator Tool line. Not every software package makes it this easy, though.

  • I only show one iCloud on my IPhone that can do a restore. I synced it with my MacBook Pro and I think that may have messed things up. Prior to that I have several backups. Will a "genius" be able to access the info I need?

    I only show one iCloud on my IPhone that can do a restore. I synced it with my MacBook Pro and I think that may have messed things up. Prior to that I have several backups. Will a "genius" be able to access the info I need?

    If things seem to be going haywire with your phone, it seems that it MAY be a software issue.
    Now, that being said, that does not necessarily mean that it is a virus. Software issues do happen sometimes. It is probably just coincidence.
    What you need to do is restore the device using iTunes. This will fix any software issues. After you have done this, you can restore from an iCloud backup.
    iCloud does not back up the actual software, so no, the "virus" would not have gotten into the backups.
    The link below provides steps on restoring your device using iTunes as well as how to restore from an iCloud backup.
    http://support.apple.com/kb/ht1766
    Don't worry! Everything should be back to normal if you follow these steps.

  • I gave my old MacBook Pro away and no longer have access to it. I didn't think to deauthorize it first. I DO NOT want it to have access to all music in my iCloud or any music that may have been downloaded sinceI gave away the computer. It now belongs to m

    I gave my old MacBook Pro away and no longer have access to it. I didn't think to deauthorize it first. I DO NOT want it to have access to all music in my iCloud or any music that may have been downloaded sinceI gave away the computer. It now belongs to my teenage daughter,who has since been in my WI-FI area and knows that code. I had EVERYTHING removed from the computer before I gave it to her (long story), but since I hadn't deauthorized the Mac,I'm assuming even without the itunes password the iCloud material would had loaded onto her computer.My iCloud had somehow included personal voice mails under Unknown Artist that I did not want on there or shared. How can I deauthorize the Mac Laptop without having the machine available to do it on? Change the iTunes/iCloud password? I should now have my desktop computer, new PC (Aspire) laptop,Ipod Touch, and if possible my Evo 3D as well as my boyfriend's Samsung smartphone being able to access the iCloud account/library--whatever it is called. HELP

    Thanks, I appreciate the help.  I think this is one of the problems Apple is creating by changing the OS so often. I had fomer colleagues at [a major aerospace contractor] who told me that so many original files were ultimately lost because of the deadly change in the "Save As" operation that they are now afraid of every OS update. Apple has badly damaged their support base with that very prominent company (they won't update now until they've fully examined and understand changes in the pre-conditioned nature of OS computer functions), and they are a whole lot less enthaled with Mac-related equipment/software. Can't blame them, I too used orginal files that way (as easy-to-use templates), and lost some important files before I realized what was happening (to late to revert). Companies should not have to retrain employees each time an OS gets an update, it's can be very expensive several different ways. They learned a painful lesson with that one. And because I'm now retired and don't use multiple devices, I need iCloud like I need a hole in the head... but I'm told there's no way to keep Apple out of my computer. Fortunately, because of major problems when initially installing Mountain Lion, one hold-over of the hardware/software damage I experienced was that iCloud can no longer access my computer even though everything else is working fine again. That was the only "good luck" I had as a result of that expensive nightmare.

  • I clicked on a link from an email that may be spam/phishing.  How can I scan my mac book pro for any viruses?

    I clicked on a link in an email that may be spam/phishing.  How can I scan my mac book pro for viruses?

    You can just download the free ClamXav and scan your entire drive - but as there are no known viruses for OS X (although there is malware - see Thomas Reed's excellent Mac Malware Guide) it's very unlikely that you have a virus.
    The best source against malware is OS X itself and common sense. Don't click on links in suspicious emails and be careful of anything that wants to install something on your computer that is not from a reputable source.
    Clinton

  • Error message when trying to add signature. An error has occurred that may be fixed by installing the latest version of the Japanese Language Support package.

    Error message when trying to add signature. An error has occurred that may be fixed by installing the latest version of the Japanese Language Support package.  How can I fix this?
    Thanks
    [email protected]

    What is your operating system?  Reader version?

  • I bought an iPad on ebay that may be stolen

    I bought an ipad on ebay that may be stolen. IT IS A HUDE DILEMMA. I have already talked to a police officer where I live but he will not file a police report.
    I will explain the situation as best as I can. I bout an ipad on ebay and it said Steve's computer and had an Apple ID of a nother perosn. I contacted that person, in an attempt to find out of he is the rightfulowner of the ipad. He said it was stolen and he is the owner. I emailed him several times and found out her never made a police report of the "stolen" ipad. I talked to Paypal and ebay in an attempt to get my mpney returned. In order to get my money returned, I need the police report. I asked the "steve" the so called owner of the iPad to make a police report. He screamed at me on the phone and said he would in no way make a police report.I asked him  why not. Then he canget his computer back. I hung up on him because he was calling me names.
    All the time the seller was ignoring my emails. (Of course, a thief's bahavior.)
    I opned a case on ebay. Then it turns out the seller has been talking to ebay representatives many times. They(ebay) emailed me many times and asked me to "work it out" with the seller. Ha! ha!
    Of course I am very angry because I have an ipad that cannot be used because it is regsitered to someone else. I cannot get my money back and, as you will learn in the next section, I cannot report it as stolen.
    I called the police and pone cam eot my house. He asked me how I got it. I explain that I bought it on ebay. Then I told him I have been emailing with who I think the owner is, Steve from somewhere in California. The officer said I should ask "Steve" to make the stolen computer report. I cannot make the stolen computer report in Hawaii, the police officer said, because the crime was committed in California.
    Now a day later I get back on ebay and the seller is communicatinbg with me suddenly. (I guess she has had a chnace to make up a plausable story.)
    She said that she sold the computer to someone on ebay.(Steve) He didn't like it and returned it to her but did not erase his ownership or apple registratiion details. She (seller on ebay) said that he is mad that she made him pay the return shipping so he is getting back at her by saying it is a stolen computer.In addition, I pleaded with this "Steve" to erase his ownership details so I can use the computer which I actually purachsed. However he refuses to erase his ownership or registration of the computer.
    This is my probelm: I want my F______ money back but the seller won't give me my money back. And ebay said for me to "work it out with the seller"
    Very funny! I am the only one who is loosing. I paid $350.00 for an iPad that I cannto even use. It may be stolen and it may not be stolen and a stupid police officer in Honolulu will not even report it.
    What can I do?
    I have the iPad. I have the serial number. Is ther a way of finind anything out about this computer with the serial number? (I would like to know if it is stolen. I would like to know who really owns it. I would like to get mymoney back and forget this crap ever happened.
    Kim 1958 just another old person with a computer

    You have a valid claim with eBay against the person who sold it to you. It was sold to you as a usable iPad. The person knew it had a persons ID on it , hence it was sold under false pretenses. Keep all your correspondence with all parties. File the claim within 60 days with eBay and Paypal. Step one is always work it out with the owner, you tried, now file the claim. If they are a legitimate business you'll get your money back, they can't afford the negative feedback. Remember the person knowingly sold you a iPad you could could never register. Misrepresenting a product is probably the number one no-no with eBay.  Good luck.

  • HT2693 Pls Pls Pls Help me my iphone is stucked on conect to itunes its not working , unresponsive,i dont know what happen with my iphone my friends telling me that may be your iphone no jailbreak , but i dont want to make this happen i dont need it.

    Pls Pls Help me >>> i bougt my iphone just 1 years ago,i dont know what happend with my iphone,its unresponsive,showing only connect to itunes ,and when i tried to restore after that messgae came on my laptop that Error 21, could not restore ,,, my friends telling me that may be somebody trying to jailbreak your mobil so this was the reason can happen but i dont want any kind of jailbreak i want my iphone back to my work plss help me i m very poor person i cant efford to buy again this phone

    Anyone have any suggestions? or is everyone else just as clueless as me !

  • Unable to update this object because the following attributes associated with this object have values that may already be associated with another object in your local directory services

    Getting this error from DirSync
    Unable to update this object because the following attributes associated with this object have values that may already be associated with another object in your local directory services: [UserPrincipalName
    [email protected];].  Correct or remove the duplicate values in your local directory.  Please refer to
    http://support.microsoft.com/kb/2647098 for more information on identifying objects with duplicate attribute values.
    Quick eyeball and couldn't see the cause in the user account so used the script here:
    http://gallery.technet.microsoft.com/office/Fix-Duplicate-User-d92215ef
    And got these outputs:
    PS C:\Windows\System32\WindowsPowerShell\v1.0> Export-OSCADUserPrincipalName -UserPrincipalName "[email protected]" -Path .\outputs.csv
    WARNING: Cannot find objects with specified duplicate user principal name
    [email protected]
    Found 0 user(s) with duplicate user principal name.
    Where to from here?
    Richard P

    Hi,
    Did you talk about the Microsoft Azure Active Directory Sync tool ?
    If yes, this issue occurs if one or more of the following conditions are true:
    An object in the on-premises Active Directory has an SMTP address that's the same as the SMTP address of the object that's reporting the problem.
    An object in the on-premises Active Directory has a mail attribute that's identical to the object that's reporting the problem.
    An object already exists in your organizational account and has the same SMTP address or mail attribute as the object in the on-premises Active Directory
    More detail information, please refer to:
    http://support.microsoft.com/kb/2520976/en-us
    [Troubleshooting] Unable to update this object because the following attributes associated with this object
    http://blogs.technet.com/b/aadsyncsupport/archive/2014/05/20/troubleshooting-unable-to-update-this-object-because-the-following-attributes-associated-with-this-object.aspx
    Regards.
    Vivian Wang

  • Indesign CS6 - 8.0 on iMac 10.9.1, a few issues that may be connected, Shutting down & PDF Issues

    Indesign CS6 - 8.0 on iMac 10.9.1, I have a few issues that may be connected:
    1. My computer shuts down goes to a black screen then restarts on its own.
    2. My InDesign will crash when I am working and there doesn't seem to be a pattern it just happens sometimes.
    3. I have an InDesign file that all of a sudden now takes 30-40mins to PDF 50 pages, I think there may be an issue with fonts but I am not sure, none of the other files take this long.

    Thank you so much for responding Bob, I tried to update but when I tired I get a message "Contact Administrator if you wish to apply updates on your machine, Updates have been suppressed by the administrator...". I actually have admin rights and I called in my IT guy, he could not get it to update. The Application Manager says I have all current updates. Am I suppoes to update using "AdobePatchInstaller"? Is there a manual way?

  • Why does adobe photoshop elements 6.0 not show up for a download choice of putting my photos into my computer, I'm on windows7.  I'm sure it did when I first got my computer.  Could it be that I have lots of other photo software that may be interfering?

    why does adobe photoshop elements 6.0 not show up for a download choice of putting my photos into my computer, I'm on windows7.  I'm sure it did when I first got my computer.  Could it be that I have lots of other photo software that may be interfering?@@

    If you open the Organizer and go to Edit>Preferences>Camera or Card Reader, do you have Auto Launch Adobe Photo Downloader on Device Connect checked?
    Try checking that if you don't.

  • HT1338 Could you please help me with the problem. I have mac os 10.7.4 on my macbook pro retina and want to update it to 10.7.5. I had been waiting for 2 hours to do it, but then it appeared that it was impossible. What should I do?

    Could you please help me with the problem. I have macbook with retina with mac os 10.7.4 ann want to update it to mac os 10.7.5. I had been waiting for 2 hours to do it and had tried 3 times but it appeared that it was impossible. What should I do?

    You can download the standalone updates:
    OS X Lion Update 10.7.5 (Client Combo)
    OS X Lion 10.7.5 Supplemental Update

Maybe you are looking for

  • Email and big wifi problems.

    Email and big wifi problems. Why does it take 6 minutes to send a photo attachment when my iphone 4 will do it in 30 to 40 seconds ? Why will my email account be recognised and log on only half the time? Why does the wifi keep dropping out? Why does

  • Disk Utility - Create encrypted disk images super sloooow

    Trying to create encrypted disk images via Disk Utility on my iMac (i7 8GB) is super-slow in 10.8.   It worked quite fast in 10.7, but now it's super-slow and doesn't even seem to ever finish. I've tried re-installing 10.8 with no difference. Anyone

  • Unable to open the events in Iphoto or transfer photos to create a book?

    Unable to open the events in Iphoto or transfer photos to create a book. The events are there but I am when double clicking they are not opening up. Also I am unable to drag photos to create a book. Any suggestions??

  • General ledger view

    Hi friends, Whenever we post the initial stock, through 561 movement type for some FI documents G/L view and entry view are not being generated, why? And Only inventory accounts are being updated and FI acconts are not updated, Why?

  • Print all (Event and Notes)

    Is there a method (script out there?) in which I can print out an iCall month or week that will include the events of the day(s) and all the notes as well. alan