How obtain all of the relationship when the table contains information of the hierarchy?
I have a table containing the information relationship MySQL master & slave, look like this,Master Slave
---------- ----------
1 2
1 3
3 4
4 5
4 6
4 7
2 8
11 12
11 13
21 22
The requirement is to gather all of the relationship in a group, the result should look like this.1,2,3,4,5,6,7,8
11,12,13
21,22
Could someone give me a tip how to do?Thanks in advance!
Best wishes
Satine
Nikolay Savvinov wrote:
Oops, I misread your original post - you want to break a together in connected groups, it's a little more complicated, sys_connect_by_path probably help here...
It is sys_connect_by_path + connect_by_root + chain aggregation (I used XMLAGG). The only question to OP is MySQL is owned by Oracle, but does not have the Oracle database and my solution won't work in MySQL. In any case:
with sample_table as (
select 1 master,2 slave from dual union all
select 1,3 from dual union all
select 3,4 from dual union all
select 4,5 from dual union all
select 4,6 from dual union all
select 4,7 from dual union all
select 2,8 from dual union all
select 11,12 from dual union all
select 11,13 from dual union all
select 21,22 from dual
),
t as (
select connect_by_root master root,
slave
from sample_table
start with master not in (select slave from sample_table)
connect by master = prior slave
)
select root || ',' || rtrim(xmlagg(xmlelement(s,slave,',').extract('//text()') order by slave),',') path
from t
group by root
order by root
/
PATH
----------------
1,2,3,4,5,6,7,8
11,12,13
21,22
SQL>
SY.
Tags: Database
Similar Questions
-
First connect by: display of all of the hierarchy even if parameter child
31%
Hello
In our case the manager_id I = employee_id for high level manager. So when I run the sql code, it eliminates the high-level manager and shows the output for the next level of leave.
For the regular start with you connect option on the employee table, the query used is
now, this will show the hierarchy and level from managers. Now, if we provide the 'start with Manager_id = 171' then as 171 isn't a Manager no row is returned. So, for this we can use something likeselect case when connect_by_isleaf = 1 then 0 when level = 1 then 1 else -1 end as status, level, First_name as title, NULL as icon, EMPloyee_id as value, First_name as tooltip, NULL as link from EMPLOYEES start with Manager_id is null connect by prior EMPLOYEE_ID = Manager_id order siblings by First_name
However, the output would be only the employee from 171 record is the last child.start with manager_id =171 or employee_id = 171
The requirement we had was that, regardless of the value entry, be it ultimate parent or child ultimate output should always display the top to the bottom of the hierarchy. from this ultimate Manager of people.
Thus, for example, if there are two employees, 170 and 171 and 170 is the Manager of 171
If in this application, I use Start with Manager = 170. He will show me the Manager and the child records.
However, if I use start with manager = 171 or employee_id = 171, then it will show me only only the registration of the child. I want that he show me the Manager and the employee records. That is, all levels
I hope that makes sense!
Thank you
Ryan
Published by: ryansun on December 12, 2012 01:13
Published by: ryansun on December 13, 2012 01:59Hello
Maybe you should post your results with different cases.
See if it fits your needs:
WITH entire_tree AS ( SELECT * FROM employees START WITH manager_id = 171 CONNECT BY PRIOR employee_id = manager_id UNION SELECT * FROM employees START WITH employee_id = 171 CONNECT BY employee_id = PRIOR manager_id ) SELECT CASE WHEN CONNECT_BY_ISLEAF = 1 THEN 0 WHEN LEVEL = 1 THEN 1 ELSE -1 END AS status , LEVEL , first_name AS title , NULL AS icon , employee_id AS VALUE , first_name AS tooltip , NULL AS link FROM entire_tree START WITH manager_id IS NULL CONNECT BY PRIOR employee_id = manager_id ORDER SIBLINGS BY first_name;
Kind regards.
Al -
How to create the hierarchy account ESSBase in OBIEE physical layer
After you import the EssBase cube in RPD, the hirerchy account is created not by default (others are created automatically as period, currency, year, etc.).
In Essbase, the account dimension has 14 people.
If I go to cube > new object > hierarchy...
Then put the details such as the name, external, name of dimension, dimension type (other), type(fully balanced) hierarchy.
What should I do after clicking the Add button? and how can I define the hierarchy?
Thanks for the help.Hello
Could be faster if you duplicate your cube in the physical layer, change the Essbase cube properties, and uncheck the account that the hierarchy of the measure hierarchy, it should ask to be displayed in the physical layer with all hierarchies, attributes as if it where any other. You can then copy this into your cube duplicated in your original.
-
When I enter the "Eubacterium' infirmum text in a cell in Excel, he eats the leading". " It's killing later logic based on obtaining all text. How to repair Excel to stop eating "of text strings?
In Excel, an apostrophe at the beginning of a text string has a special meaning as a character of text-alignment prefix . To start a string with an apostrophe, type two of them.
-
How can I get the new tab to open all the way to the right of the tabs old when I use the link open in a new tab?
Set the pref browser.tabs.insertRelatedAfterCurrent false on the subject: config page.
To open the topic: config page, type Subject: config in the address bar (address) and press the 'Enter' key, as you type the url of a Web site to open a Web site.
If you see a warning then you can confirm that you want to access this page.
You can use the filter at the top bar of the on: page config to more easily spot a pref. -
We have 2 phones and 2 computers and they all sound when the phone rings. How to change that? they all use the same apple - ID we buy apps and music coming from the same account. It all works very well, but we don t like any other device to RING eveytime a phone rings.
Thank you so much: D
ON both phones, check the settings > phone > call on other devices > Off.
-
Hello guys, I have a 32 GB IPad 3 with an operating system of ios 9.2.1 this problem has never happened before and what happened, it's just a normal day and the iPad was running smooth as always until there was suddenly a notification when I opened my iPad from YouTube, so I opened it and all of a sudden when I opened the application crashed and I was on the home screen and all records have were missing, though safari and app store were in a folder so they disappeared in Buthan, I went to the settings and all applications have plaseeeeeeee someone tell me how to solve this problem
Try to keep the sleep/wake and the "home" button until the Apple logo appears. -AJ
-
How I picked my email address when I don't have an alternative email address to reset and also the mobile operator I'm using is not listed it at all.
Hotmail gives me a few options, but non of them is useful to me...
The problem is probably my junk e-mail generated from my e-mail address or something else, I don't know about you!
Thank you
Hi Beqiri2012,
Just to clarify, please repost your question on the Hotmail Forums below to help with your Hotmail account number:
http://windowslivehelp.com/forums.aspx?ForumID=d3fda415-1e53-4007-8e0c-2a77180ffb1d
Thank you!
-
How can I disable the Preview on my desktop icon, I have many files on my desktop, it's easier when all of the PDF files have the same icon instead of a preview icon. so, I immediately see who is PDF and DWG. at the moment they all look different because the icon shows a preview of the contents of the file.
Hi Khody,
To change your windows 7 application icon you can use following the procedure-
a. Right click on the desktop icon and then click Properties.
b. now Select the shortcut tab and see button below to change the icon. Click the button change icon now all the icons.
c. you can choose a of the icons that you want for the shortcut.I hope this helps.
-
I'm new to using Windows 7, I did a "new folder" to put pictures in, how can I do this? When I select all and right click to add photos to my account, I don't see the folder...
Drag and drop the video,
http://www.YouTube.com/watch?v=6n3YKsgOdsk
Or right-click and use cut then right click on the folder and select Paste.
-
I use LRM6 with Win7. Cannot display all of the subfolders on external drive with photos. Can't see most recent used folders. How can I get all the records to display in the tree when the library module?
Syrup72 wrote:
Why I see pictures when I click on the tab all the photos above, which do not show in the tree on the G: drive?
DSC_2429 is in the shown locaton and present in all the Photos, but there is no folder "Tulsa"... "in the tree.
The left pane is a "choose one". "All photos" are just that. 'G' is a different option.
Lightroom is not a file Explorer. He knows only the drives and files that you have imported the photos of. If LR shows not all of the photos that are on your hard drive, it is because you did not import all photos.
If LR shows you a photo in "all photos" but do not show it in the folder you think he is in, go to "all photos", select the image, right click "view in the library folder. This will show you where LR think the picture is.
-
ADE 4.5 keeps freezing ("not responding") when I plug my Bebook mini E drive. When I unplug the E drive it immediately starts working again. I tried different versions of the ADE (2.0, 3.0, 4.0, 4.5) but they all have the same question. How can I fix?
His player on this list: Adobe Digital Publishing Solution?
-
How to register for the web when all options gif gives me an error message?
How to register for the web when all options gif gives me an error message? I have a tent to save a cinemagraphs.com second 8 and me still get an error message.
Hi badasshe,
Please reset the Photoshop preferences and then try.
Steps to follow:
To re-create the Photoshop preferences files, start the application while pressing Ctrl + Alt + Shift (Windows) or command + Option + shift (Mac OS). Then, click Yes to the message, "Delete the Adobe Photoshop settings file?"
Reference: preference file works, names, places | Photoshop CS5
Let us know if it helps.
Kind regards
~ Mohit
-
I DELETED MY PDF FILES AND AGAIN USING THE RECOVERY SOFTWARE I FIND ALL MY FILES BUT NOW WHEN I OPEN FILES THAT IT SHOWS (THE FILE MAY BE CORRUPTED OR NOT SUPPORTED FORMAT.NO HOW CAN I OPEN THE FILES.) ALL OF THEM ARE MY DOCUMENTS IS VERY IMPORTANT. PLEASE PROVIDE ME WITH A
Deleted file recovery can recover incomplete files, i.e. the part of these files may be missing. Recover deleted files is much more reliable if recovery of a backup, instead of using recovery software.
These things depend on the operating system and the file system.
One thing, you can see: open one of these files damaged with a text editor, and then make sure that the constant % PDF is somewhere in the first 1024 bytes.
PS please do not post ALL uppercase; It is very difficult to read!
-
In fact, I have problem in adding music to be played across all folios, the problem happened when I simply lock the ipad and open it, the publication is always open and I can browse, but the music stops and cann't continue. How can I solve this problem to continue after the opening of the ipad and continue to navigate the digital publication.
The background sound plays only if the application is open. Once the device is locked or the user switches to another application the audio will stop.
Maybe you are looking for
-
How can I uninstall the toolbar from firefox
Inadvertently, I installed the firefox toolbar while seeking manual parts. I would like to remove it, but it does not appear on my program list.
-
I have a HP pavilin elite model # hpe - 480 t. What advice due I need to upgrade to usb 3.0
-
No Signal after installing new graphics card
Hello and thank you in advance for your help! We have a 2 years old HP p6540y. It has an ATI video card integrated. When we recently turned on, we got a message "no signal" on the monitor and then he'd go to sleep. We tried many things to fix... li
-
Hello I have problem after restoring my iphone 6 1 or 2 weeks ago, I put my apple with this id * but ID not enable find my iphone, this time, my ios is 8.4. before that I didn't put everything on icloud my iphone apple ID 6. before restoring already
-
BSOD on reboot after installing the patch MS10-046
I installed the critical patch MS10-046 on a netbook under XP SP3. On reboot, bsod with error message: "The Shell32.dll image is possibly corrupt. The header checksum does not match the checksum calculated. » The only way to start was via a USB key.