Heirarchy query - Need help please!
DB ver: Oracle DB 10g Rel2
I have data as follows
LAST_NAME EMPLOYEE_ID MANAGER_ID
King 100 null
Cambrault 148 100
Bates 172 148
Bloom 169 148
Fox 170 148
Ozer 168 172
Smith 171 172
De Haan 102 169
Hunold 103 169
Austin 105 169
Ernst 104 170
When Cambrault(emp.id:148) logs in he should see the reporting structure as follows
- Cambrault
-- Bates
--- Ozer
--- Smith
-- Bloom
--- De Haan
--- Hunold
--- Austin
-- Fox
--- Ernst
Similerly when Bates(Emp.Id:172) logs in he should see as follows
- Bates
-- Ozer
-- Smith
How to write a query to get output of records as above?
I could write it as follows but getting all the records.
SELECT e1.ename||' works for Supervisor '||e2.ename
FROM emp e1, emp e2
WHERE e1.mgr = e2.empno;
Any help is highly appreciated. Thanks in advance.
movva
Edited by: cmovva on 27-Oct-2011 12:07 PM
maybe this example might help.
SQL> select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7902 FORD ANALYST 7782 03-Dec-81 3000.00 20
7839 KING PRESIDENT 17-Nov-81 5000.00 10
7698 BLAKE MANAGER 7839 01-May-81 2850.00 30
7782 CLARK MANAGER 7839 09-Jun-81 2450.00 10
7788 SCOTT ANALYST 7782 09-Dec-82 3000.00 20
7844 TURNER SALESMAN 7698 08-Sep-81 1500.00 0.00 30
7876 ADAMS CLERK 7782 12-Jan-83 1100.00 20
7900 JAMES CLERK 7698 03-Dec-81 950.00 30
7934 MILLER CLERK 7782 23-Jan-82 1300.00 10
7945 CINDY SALESMAN 7698 16-Jan-83 1800.00 30
7950 TINA SALESMAN 7698 18-Jan-83 1850.00 30
11 rows selected
SQL>
SQL> select substr(lpad(' ',2*(level-1)) || ename,1,40) employee_name, job, hiredate, sal
2 from emp
3 start with mgr is null
4 connect by prior empno = mgr;
EMPLOYEE_NAME JOB HIREDATE SAL
KING PRESIDENT 17-Nov-81 5000.00
BLAKE MANAGER 01-May-81 2850.00
TURNER SALESMAN 08-Sep-81 1500.00
JAMES CLERK 03-Dec-81 950.00
CINDY SALESMAN 16-Jan-83 1800.00
TINA SALESMAN 18-Jan-83 1850.00
CLARK MANAGER 09-Jun-81 2450.00
SCOTT ANALYST 09-Dec-82 3000.00
ADAMS CLERK 12-Jan-83 1100.00
FORD ANALYST 03-Dec-81 3000.00
MILLER CLERK 23-Jan-82 1300.00
11 rows selected
SQL> using your sample data something like this:
SQL> select *
2 from (select 'King' last_name, 100 employee_id, null manager_id from dual union all
3 select 'Cambrault' last_name, 148 employee_id, 100 manager_id from dual union all
4 select 'Bates' last_name, 172 employee_id, 148 manager_id from dual union all
5 select 'Bloom' last_name, 169 employee_id, 148 manager_id from dual union all
6 select 'Fox' last_name, 170 employee_id, 148 manager_id from dual union all
7 select 'Ozer' last_name, 168 employee_id, 172 manager_id from dual union all
8 select 'Smith' last_name, 171 employee_id, 172 manager_id from dual union all
9 select 'De,Haan' last_name, 102 employee_id, 169 manager_id from dual union all
10 select 'Hunold' last_name, 103 employee_id, 169 manager_id from dual union all
11 select 'Austin' last_name, 105 employee_id, 169 manager_id from dual union all
12 select 'Ernst' last_name, 104 employee_id, 170 manager_id from dual) e;
LAST_NAME EMPLOYEE_ID MANAGER_ID
King 100
Cambrault 148 100
Bates 172 148
Bloom 169 148
Fox 170 148
Ozer 168 172
Smith 171 172
De,Haan 102 169
Hunold 103 169
Austin 105 169
Ernst 104 170
11 rows selected
SQL>
SQL> select substr(lpad(' ',2*(level-1)) || e.last_name,1,40) last_name,
2 e.employee_id,
3 e.manager_id
4 from (select 'King' last_name, 100 employee_id, null manager_id from dual union all
5 select 'Cambrault' last_name, 148 employee_id, 100 manager_id from dual union all
6 select 'Bates' last_name, 172 employee_id, 148 manager_id from dual union all
7 select 'Bloom' last_name, 169 employee_id, 148 manager_id from dual union all
8 select 'Fox' last_name, 170 employee_id, 148 manager_id from dual union all
9 select 'Ozer' last_name, 168 employee_id, 172 manager_id from dual union all
10 select 'Smith' last_name, 171 employee_id, 172 manager_id from dual union all
11 select 'De,Haan' last_name, 102 employee_id, 169 manager_id from dual union all
12 select 'Hunold' last_name, 103 employee_id, 169 manager_id from dual union all
13 select 'Austin' last_name, 105 employee_id, 169 manager_id from dual union all
14 select 'Ernst' last_name, 104 employee_id, 170 manager_id from dual) e
15 start with e.manager_id is null
16 connect by prior e.employee_id = e.manager_id;
LAST_NAME EMPLOYEE_ID MANAGER_ID
King 100
Cambrault 148 100
Bloom 169 148
De,Haan 102 169
Hunold 103 169
Austin 105 169
Fox 170 148
Ernst 104 170
Bates 172 148
Ozer 168 172
Smith 171 172
11 rows selected
SQL>
Similar Messages
-
How can I add a new Template to My Templates in Pages? I've read most of the discussions on the subject but it doesn't work for me. By the time I reach the Templates folder, I only see templates for Numbers and not for Pages. Need help, please. Thanks
Si vous avez utilisé la commande Save As Template depuis Pages, il y a forcément un dossier
iWork > Pages
contenant Templates > My Templates
comme il y a un dossier
iWork > Numbers
contenant Templates > My Templates
Depuis le Finder, tapez cmd + f
puis configurez la recherche comme sur cette recopie d'écran.
puis lancez la recherche.
Ainsi, vous allez trouver vos modèles personnalisés dans leur dossier.
Chez moi, il y en a une kyrielle en dehors des dossiers standards parce que je renomme wxcvb.template quasiment tous mes documents Pages et wxcvb.nmbtemplate à peu près tous mes documents Numbers.
Ainsi, quand je travaille sur un document, je ne suis pas ralenti par Autosave.
Désolé mais je ne répondrai plus avant demain.
Pour moi il est temps de dormir.
Yvan KOENIG (VALLAURIS, France) mercredi 23 janvier 2011 22:39:28
iMac 21”5, i7, 2.8 GHz, 4 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.2
My iDisk is : <http://public.me.com/koenigyvan>
Please : Search for questions similar to your own before submitting them to the community -
I am trying like **** to download itunes 10.6.3 (64 bit - Windows 7) and I keep getting "the installer was interrupted before the requested operations for iTunes could be completed. Your systems has not been modified." I NEED HELP, PLEASE!
I got it figured out myself... yaaaaay for me!
-
After my iphone4S update to 7.0.6, it have a problem that keep searching network then no service show on display. Can't call. I have try check sim card, reset network settings, and restore my iphone. Still not working at all. Need help please.Urgent.TQ
Izit software or hardware? Confuse:(
Only can use wifi now.
Any way thanks guys for ur suggestion:) amishcake and simes -
Bought a new macbook and want to manually manage music onto my iphone 4s (as it is already full of music from old windows laptop) but when i click 'manually manage' and then 'apply' i get the message saying it will erase everything already on there. Need help please!
Before you sync your iPhone make sure that all the music that was synced to your phonereviously has been copied to your iTunes on the new MacBook Pro. Then when you connect your phone you will be able to either sync all music or select only those playlists that you want on the phone.
-
Hi i need help please i been playing clash of clans over 13 months. And today o realise what someone using my game Centra. Someone playing on my game Clash of Clans. I been change my Apple ID password, email, but doesn't work. Then I playing game I can see what someone else trying connecting to my game And I don't know what to do.So if you can help me please? I don't wanna lose my game.
Contact iTunes
Contact iTunes -
Hi i need help please i been playing clash of clans over 13 months. And today o realise what someone using my game Centra. Someone playing on my game Clash of Clans. I been change my Apple ID password, email, but doesn't work. When I playing game I can see what someone else trying connecting to my game And I don't know what to do.So if you can help me please? I don't wanna lose my game.
Hello Vaidas Vaidas,
It sounds like you are noticing someone else is accessing your Clash of Clans data by playing the game and you have tried to reset your Apple ID password. If you are following the steps outlined in this article:
Apple ID: Changing your password
http://support.apple.com/kb/ht5624
What is preventing you from changing your password? Any error messages or prompts?
Thank you for using Apple Support Communities.
All the best,
Sterling -
i dont know how i got my photos to my ipod touch from my pc and now i wanna delete them but couldn't. so need help. please let me know.
To turn off auto sync - launch iTunes and go to Edit>Preferences>Devices - check the box at the bottom that says - Prevent iPod, iPhones and iPads from syncing automatically. Click OK and then quit iTunes.
Connect your iDevice to your PC.
Launch iTunes,
Click on the device name on the left side of the iTunes Window.
Click on the Photos Tab in the iTunes window on the right.
Untick all of the photos or albums that you want to remove.
Click on Apply in the lower right corner of iTunes
If you untick or uncheck the Sync Photos heading and then click Apply it will remove all of the photos from the device when it syncs. In this screenshot - I have only certain albums and events selected to sync. -
My iPhone 6 can't find my macbook pro on the airdrop list, although everything is in place, bluetooth, wi fi gets, need help please ?
Dear Niel, thank you but my mac is (MacBook Pro (Retina, 15-inch, Early 2013).
and i can send from it to my iPhone , but not vice versa -
After many months of non-use, when I tried to open Photoshop CS4 Extended, I got an error message 148.3. "Licensing for this product has stopped working." I need help, please.
Error "Licensing has stopped working" | Windows
Error "Licensing has stopped working" | Mac OS
Mylenium -
I need help please I keep getting error messega 21 when i try uploading my iPhone 4 s!!!!!!!!! omg some one please tell me if and how to fix this please. thank you!!!
Hopefully this link will help you: http://support.apple.com/kb/HT2109
-
Hello, I,m having problems with Polish spell check. It says in iPnstruction that this App (pages) should show my writing mistakes. Check spell button is on but but check spell is not working. Need help Please.
Hello, I,m having problems with Polish spell check. It says in iPnstruction that this App (pages) should show my writing mistakes. Check spell button is on but but check spell is not working. Need help Please.
-
After updating my Iphone 5 my lock button isnt working well .... Need help please ..
First, read here:
https://ssl.apple.com/support/iphone5-sleepwakebutton/
See if your phone is affected. -
hi
i need help please . when i want to buy app from store ask me the security question
but i forgot the answer
so i need to the link to rest answer of security questionThe Best Alternatives for Security Questions and Rescue Mail
a. Send Apple an email request at: Apple - Support - iTunes Store - Contact Us.
b. Call Apple Support in your country: Customer Service: Contact Apple support.
c. Rescue email address and how to reset Apple ID security questions. -
Hi I need help please .... I have my credit card information in my account ... But I wanted to delete & I like too add a App Store card
Hi, Ajchenicholas.
Credit cards attached to an Apple ID can be removed and payment method changed to none as long as there is not an outstanding balance. The article below will walk you through this process.
iTunes Store: Changing account information
http://support.apple.com/kb/ht1918
You can always add an iTunes Gift Card to your account at any time. Here are the steps that will walk you through adding an iTunes Gift Card.
iTunes Store: How to redeem a code
http://support.apple.com/kb/ht1574
Cheers,
Jason H.
Maybe you are looking for
-
Table fields to match pdf form
I found this on my formscentral help file. Note: Some types of form fields aren't supported when you import a PDF form. For example, text fields with formatting applied, such as numeric or percentage fields, are converted to plain text fields. And, s
-
How to override setText for custom JButton
Hi From the Swings Hack book, I have the code for a custom JButton. I would like to setText for this button so that the text is set over the image on the button. Would someone know how I can do this? import java.awt.*; import javax.swing.*; public cl
-
Re-name worksheet tabs from cell contents?
Is is possible to re-name worksheet tabs automatically from cell contents in another sheet within the same workbook? I have a workbook with 30 sheets all feeding data into sheet 31 - the Master Worksheet where all the data is collated etc. There are
-
Hi Friends, I am configuring the receiver JMS adapter- 1.In the JMS Settings section there is a option called "JMS ReplyTo Queue Name". I am not sure about the significance of it. 2.Also let me know whether it is mandatory to fill? I have seen few bl
-
Did CS4's multiple artboards kill any crop area capabilities?
I'm still gobsmacked by the multiple artboard stuff... but I see my favorite CS3 feature, multiple crop areas is gone (or at least appears to be gone). I came to depend rather heavily on multiple crop areas -- so I'm anxious that some facet of them c