Identify the IDS that relate to each other?

Hi all

I would appreciate some advice with a special query that is run please. I use Oracle 10 g.

I'm looking to identify children who relate to each other using their extended family relationships where they do not share a direct relationship.

I have two tables:

1 - my_children. This table has a view of the children interested.

2 - all_relations. It has 3 main passes that identifies the relatives of people in my_children and other relatives (see code below). Rel_ID2 is the ID of who have somehow relate to rel_ID1 (child_id). Rel_type explains how they relate (e.g. mother/father/sister/many others).
select * from
my_children mc,
all_relations ar
where mc.child_id = ar.rel_id1(+)
order by child_id
My_children children can share a relationship between them directly (i.e. sibling) or indirectly i.e. child1 concerns child2 (cousin) mother's brother (or any number of steps) but! cannot be entered directly as cousin/cousin (Data Quality). What is important is that there should be a relative ID string to each other through rel_ID1 and rel_ID2.

Using the table of all_relations, I need to identify what children in my_children relate to each other and assign them a value that identifies that they relate each other. This can be done by using a common rel_id or a general value, depending on what is more simple.

I think that this could be done with something like
Starts With Child_ID is not null CONNECT BY PRIOR rel_ID1 = rel_ID2
but I don't understand queries line enough to make it work in this context. I can't use the PL/SQL I need to deploy in another application.

Create tables below. desired1 is the endpoint that interests me. For example, ID A2000 connects indirectly to ID A5592 A4481 and A6000 but A2000 is not A5592 immediately.

So thanks a lot if someone can recommend an approach to this.

Create the table my_children
(child_id varchar (5),)
child_name varchar (20));

insert into my_children (child_id, child_name) values ('A1000', "John Benson");
insert into my_children (child_id, child_name) values ('à1453', "Alice Ronson");
insert into my_children (child_id, child_name) values ('A1822', 'Sarah Jones');
insert into my_children (child_id, child_name) values ('A2000","Mary Watson");
insert into my_children (child_id, child_name) values ('A5592', 'Harry Smythe');


create the table all_relations
(rel_pk varchar (5),)
rel_id1 varchar (5),
rel_id2 varchar (5),
rel_type varchar (20));

insert into all_relations (rel_id1, rel_id2, rel_pk, rel_type) values ('R1349', 'A1000', 'A1459', 'Mother');
insert into all_relations (rel_id1, rel_id2, rel_pk, rel_type) values ('R1546', 'A1000', 'À1453', 'Sister');
insert into all_relations (rel_id1, rel_id2, rel_pk, rel_type) values ('R1941', 'À1453', '1973', 'Nièce');
insert into all_relations (rel_id1, rel_id2, rel_pk, rel_type) values ('R1969', '1973', 'A3489', 'Sister');
insert into all_relations (rel_id1, rel_id2, rel_pk, rel_type) values ('R2954', 'A1822', 'A1000', "Half-sister");
insert into all_relations (rel_id1, rel_id2, rel_pk, rel_type) values ('R1301', 'A2000', 'A1359', 'Sister');
insert into all_relations (rel_id1, rel_id2, rel_pk, rel_type) values ('R1366', 'A2000', 'A1359","Cousin");
insert into all_relations (rel_id1, rel_id2, rel_pk, rel_type) values ('R1998', 'A1359', 'A2000', 'Sister');
insert into all_relations (rel_id1, rel_id2, rel_pk, rel_type) values ('R3491', 'A2000', 'A4481', 'Brother');
insert into all_relations (rel_id1, rel_id2, rel_pk, rel_type) values ('R3450', 'A4481","A6000","Half-brother");
insert into all_relations (rel_id1, rel_id2, rel_pk, rel_type) values ('R7542', "A6000", "A5592', 'Half-twin');
insert into all_relations (rel_id1, rel_id2, rel_pk, rel_type) values ('R3889', 'A4498', 'A2213","Other");


create the table desired1
(child_id varchar (5),)
child_name varchar (20),
famgrpflag varchar (5));

insert into desired1 (child_id, child_name, famgrpflag) values ('A1000', 'John Benson","ZZZZ1");
insert into desired1 (child_id, child_name, famgrpflag) values ('à1453', 'Alice Ronson', 'ZZZZ1');
insert into desired1 (child_id, child_name, famgrpflag) values ('A1822","Sarah Jones","ZZZZ1");
insert into desired1 (child_id, child_name, famgrpflag) values ('A2000","Mary Watson","ZZZZ2");
insert into desired1 (child_id, child_name, famgrpflag) values ('A5592', 'Harry Smythe', 'ZZZZ2');

Hello

Here's a way to do what you asked:

WITH     connect_by_results     AS
(
     SELECT     rel_id1                    AS rel_id
     ,     CONNECT_BY_ROOT     rel_id2          AS root_rel_id
      FROM     all_relations
     CONNECT BY NOCYCLE     rel_id1     = PRIOR rel_id2
          OR           rel_id2     = PRIOR rel_id1
    UNION ALL
     SELECT     rel_id2                    AS rel_id
     ,     CONNECT_BY_ROOT     rel_id1          AS root_rel_id
      FROM     all_relations
     CONNECT BY NOCYCLE     rel_id1     = PRIOR rel_id2
          OR           rel_id2     = PRIOR rel_id1
)
,     got_grp_id     AS
(
     SELECT       rel_id
     ,       MIN (root_rel_id)     AS grp_id
     FROM       connect_by_results
     GROUP BY  rel_id
)
SELECT       c.*
,       g.grp_id
FROM       got_grp_id     g
JOIN       my_children     c  ON     c.child_id     = g.rel_id
ORDER BY  g.grp_id
,            c.child_id
;

Output:

CHILD CHILD_NAME           GRP_I
----- -------------------- -----
A1000 John Benson          A1000
A1453 Alice Ronson         A1000
A1822 Sarah Jones          A1000

A2000 Mary Watson          A1359
A5592 Harry Smythe         A1359

The grp_id is the first child_id (in alphabetical order) that each line is connected, which must not be my_children.
For the abstract grp_ids, use DENSE_RANK to map each grp_id to a single value. In other words, change the main query

SELECT       c.*
,       LPAD ( DENSE_RANK () OVER (ORDER BY  g.grp_id)
            , 5
            , 'Z'
            )          AS famgrpflag
FROM       ...

Everything can stay the same as above. Output:

CHILD CHILD_NAME           FAMGRPFLAG
----- -------------------- ----------
A1000 John Benson          ZZZZ1
A1453 Alice Ronson         ZZZZ1
A1822 Sarah Jones          ZZZZ1

A2000 Mary Watson          ZZZZ2
A5592 Harry Smythe         ZZZZ2

Thanks for posting the CREATE TABLE and INSERT. Instead of posting the results desired in a table, it would be more useful (and less confusing) If you posted at the exit.

Little Penguin says:
... I think that this could be done with something like

Starts With Child_ID is not null CONNECT BY PRIOR rel_ID1 = rel_ID2

Exactly! But don't forget the reflexive nature of your data. It looks like what you call rel_id1 and rel_id2 are arbitrary, at least sometimes. For example, instead of:

insert into all_relations (rel_pk, rel_id1,rel_id2, rel_type) values ('R1366', 'A2000', 'A1359', 'Cousin');

as well, you could say:

insert into all_relations (rel_pk, rel_id1,rel_id2, rel_type) values ('R9999', 'A1359', 'A2000', 'Cousin');

you shouldn't do both. So whatever you do with rel_id1 and rel_id2, you also have to do with rel_id2 and rel_id1 (that is, with the inverse ID).

Tags: Database

Similar Questions

  • I have a document composed of separate PDF files that reside in a folder and are related to each other through hyperlinks. Each pdf file is set to open with bookmarks displayed, however if I have a link to a PDF file to another and use the button "Previou

    I have a document composed of separate PDF files that reside in a folder and are related to each other through hyperlinks. Each pdf file is configurΘ for dΘmarrer with bookmarks displayed, however if I have a link to one PDF file to another and use the "back" button to return to my starting point bookmarks are replaced by "vignette". Is there anyway to prevent this?

    Hi Mike,.

    While the implementation of the links, if you choose to open the file in a new window then you will not experience this issue, then you can simply switch to the file view and previous bookmark will remain as it is.

    Is that what helps with your query?

    Kind regards
    Rahul

  • How to identify the data that is associated with any book in crm on demand?

    We are experimenting with books, but I have yet to find an easy way to identify the data that are not associated with any book.

    Do you have a suggestion?

    I discussed this with Oracle in recent years CAB, but we have no indication if it will be included, but it could be part of their 'User' hotel subject they are studying.

  • Why can I not see the tabs that are on my other computer?

    I have synced with another computer and it is said that it is connected and I can see my favorites, but why can't I see the tabs that I frequently use on another computer?

    History > 'tabs on other computers.

  • How can I delete the stuff that loads automatically each time I start my computer? MS Messenger in particular.

    I have some programs that load at startup to the top.  There are a couple of them that I would like to delete.  In particular, I would like to get rid of MS Messenger that doesn't even exist anymore.  How do I know what charges at first upward and how to remove the things that I do not want to load.  Some are programs that I use, but I don't need to load every time I turn on my computer.

    There is a tool that you can use to find out what is running at startup.

    "This utility, which has a knowledge of auto-starting locations of any startup monitor, shows you what programs configured to run at system startup or login and that the entries in the order Windows treatment."

    Autoruns.

    http://TechNet.Microsoft.com/en-us/sysinternals/bb963902.aspx

    Basic use of Autoruns.

    http://www.YouTube.com/watch?v=HhtSDsQYi28

  • The duplicate files. Same file appears in different directories - how to identify the programs that use these files?

    Hello

    Question 1 - I have a list of duplicate on my computer files. Very often, the same file appears in two or more different locations. So I guess this could mean different copies of the same file is used by various programs. It would then be important to know what program is using this file prior to the removal of duplicates.

    Question 2 - it would be possible to point all programs that use a file given in one place? That is to centralize the location of a file. What I think, could eliminate the need to have different copies at different locations. If so, how is it please?

    Thank you for your help.

    The duplication that you see is the result of a bad installation program written by eSupport. It has nothing to do with Microsoft. I could do this:

    1. Rename the folder c:\eSupport in eSupport.junk
    2. Wait a week or two.
    3. If all goes well, remove the renamed folder.
  • identify the tables that are affected by a transaction

    Hi guys,.

    I am running version:

    Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production
    PL/SQL Release 11.2.0.3.0 - Production
    CORE Production 11.2.0.3.0
    AMT for Linux: Version 11.2.0.3.0 - Production
    NLSRTL Version 11.2.0.3.0 - Production



    Is it possible to identify the SQL code or the tables involved in a transaction by looking at the transaction$ v?

    Just wrote a small application, but can't test it in my DB... Just check it...
    Basically CREATE all the views will provide some information.

    SELECT t.ses_addr,
           s.sid,
           p.object_id,
           D.OBJECT_NAME,s.command
      FROM v$transaction t,
           v$session s,
           V$locked_object p,
           dba_objects d
     WHERE     t.ses_addr = s.saddr
           AND p.session_id = s.sid
           AND d.object_id = p.object_id;
    

    The command column is a code displays what kind of operation is being currently... the explanation of the code can be mentioned in the documentation:

    http://docs.Oracle.com/CD/B19306_01/server.102/b14237/dynviews_2088.htm

    See you soon,.
    Manik.

  • I'm pulling my hair out trying to identify the parameter that prevents the background scroll

    CSS code below

    {body

    text-align: center;

    make-style: normal;

    Police: 100% Verdana, Arial, Helvetica, without serif.

    do-size: 12px;

    Color: #000;

    background-image: url('/images/bg.gif');

    background-attachment: scroll;

    background-position: top center;

    left margin: 0px;

    margin-right: 0px;

    margin-top: 0px;

    margin-bottom: 0px;

    Top: 0px;

    float: left;

    Width: 100%;

    }

    I need the image that will be implemented horizontally but vertically scroll. Any help would be greatly appreciated.

    You have changed it in your CSS, but you have that yourthat is overwhelming. Delete this whole section of your page and it works.

    {body

    background-color: transparent;

    background-repeat: no-repeat;

    background-attachment: scroll;

    }

    You should also remove position: absolute of your body in the CSS file. It is not necessary.

  • Why is it so hard to find an answer in the help of Firefox (704 returns does NOT help me answer my simple question ONE, which was: How can I turn off the feature that keeps blocking each download I try to?)?

    FF10. Whenever I try to download a file, it blocks the transaction with a Ribbon of Windows Internet Explorer style in the upper part of the window. It's very annoying. How do I turn it off? I can't browse 700 + feedback on the help search.

    I can't now to reproduce the problem. It seems to have disappeared on its own. She gave me a small strip in the upper part of the window below the menu bar of Firefox. I think the banner said "Firefox has blocked a website tries to download a file on your computer" and there is a button on the right marked "allow." I thought that there was a framework for that somewhere and the other to block redirects and now I can't find neither. I got v.9.0 and he auto-mis to day to 10.

  • How can I check if someone has logged on to my computer in the apartment that I share with other 4...

    .. .is a preserved journal of last time computer was turned on and connected?

    Hi Tyrone,

    While you should follow the advice of ahaap, maybe this could help in the meantime:

    Go to Control Panel / administrative tools / observer of events and double click to open it.

    On the left, expand Event Viewer Local (if not already done), and then expand Windows logs and then click Security to view the security event.  They should be sorted by date.  When the computer starts, there are usually plenty of events that occur.  Search Login task category (there may be also a large number of them, some who have succeeded and some failed and some for the users of the system and others for regular users) and you should be able to see then not only the last time that a connection has occurred, but exactly what the user connected (although you may need to go through a few entries to find the information you want).

    I hope this helps.

    Good luck!

  • My Media Center has stopped working on Xbox; now that they find each other

    I've lived almost every link and FAQ and troubleshooting, thing that I can find and nothing has worked.

    I use my Xbox 360 as an extender for Windows Media Center for more than a year or so now.  I changed nothing and suddenly it no longer works.  I tried playing with the firewall, even turn it off at some point and usually still Media Center to connect to the Xbox.  I get as far as enter the 8-digit code in the Media Center and it won't find the Xbox.

    The ONLY thing that has changed on my computer in the last few days has been an update to Kaspersky the other night.  I left out of it just to try and still no luck.

    I did all the General stuff, any reboot, soft and hard resets to the router and the wireless router.  This is my Xbox connects to the internet without any problem, just not the Media Center.

    I have no idea what to do next.

    Thank you for any response.

    Hi Cactus19,

     
    Welcome to the Microsoft community. According to the description of the problem, I realized that you have a problem with connecting to Windows Media Center.
     
     
    I would suggest trying the following methods and check the status of the issue.
     
     
    Method 1:
    I suggest that you check the Media Center log in the event viewer and let us know what errors are appearing.

    Open event viewer.

    http://Windows.Microsoft.com/en-us/Windows7/open-Event-Viewer

    Method 2:

    While trying to use your Xbox 360 as a Media Center Extender console, you receive the error message: "Setup error".

    Method 3:

    Restore the system to a system restore point where everything was fine.

    The system restore.

    http://Windows.Microsoft.com/en-us/Windows7/products/features/system-restore

    If the problem persists, I would say you send additional information to help you further, we will be happy to help you.

  • How can I identify the program that turns my internet access?

    Normal mode startup I get an IP address from my router but no internet access, cannot ping the router IP address or IP address of another computer on the local network.  I ping my own IP address.  I can access the internet if I start my computer in Safe Boot w/Internet.  I'm guessing that a program is power off or blocking the ability of network cards to talk beyond my computer during startup.  There are system variables, I can look at, or a list of programs that need to run, so that I can turn off others and test to see if the network works? This problem affects both my Wi-wired connections and my computer.  They both Act the same way.  I even installed a second adapter USB wireless as a test and it also reaches the router initially and then won't talk to her after the security negotiation.  McAffee software detects no virus on the system and no virus found or deleted in the previous analysis of the reports.  The problems started when I rebooted my machine to get the sound to work.   I had been running without the speakers connected and found the sound does not when I plugged.   The only known software update was of Flash Player, but I see no way out with a restore point, which is days of May and was generated from a Windows Update.  Everything worked fine after that Windows Update including the speakers.   I need help, or will be forced to recreate the image on my machine, I want to avoid.

    McAfee has been updated at the same time as the last batch of updates from Windows 7 and this is the cause of problems of internet connection for most, if not all, users of McAfee.

    See the communication from this "criticism" - McAfee

    Some customers may experience a loss of network connectivity and/or errors in McAfee Security Center after a recent update

    You should make the fix McAfee, if necessary. There are corresponding communications for their enterprise products.

    I had to run the removal of McAfee Development tool a few times before and it caused a problem with the license if the PC was not connected to the internet during the abduction. Due cat of McAfee support reset their files in order to allow the relocation-reactivation. Here is their link cat - McAfee - media contains the link to the cat

  • When the OSM is stacked on each other, how get you a desired to appear first?

    Hello - I have several ESM legend (legend status, more appear and disappear States) in the same exact place in an article. How can I get the appropriate injector appears on the load? I tried to push this layer to the top above all others, but that doesn't seem to do the trick.

    Thanks in advance

    Why not combine them into one?

  • How to identify the orders that have been picked but not delivered

    Anyone now of a report or have a few sql they could share? I am trying to identify all the commands/lines that have completed the process of gathering, but have not been closed/shipped yet confirmed.

    You can make one of these

    (1) shipping transactions form and status of line queries intermediary/Pick confirmed

    (2) find the reservations and form (F11 mode) query for status Pick free shipping

    Thank you
    Karthik.

  • How can we identify the code that triggered the promotion discount in order?

    Hello

    As we can create coupons and promotions assign them to give discounts. How can we identity coupon code that is added to the promotion which caused the discount in order?

    Kind regards

    Chede

    I give you an example. Here's how you do it from the order level promotions. OrderImpl (object) (API below give you orderpirceinfo and second link gives adjustments.)

    http://docs.Oracle.com/CD/E35319_01/platform.10-2/APIDoc/ATG/commerce/order/OrderImpl.html#getPriceInfo )

    OrderPriceInfo that extends AmountInfo, the following method gives adjustments

    http://docs.Oracle.com/CD/E35319_01/platform.10-2/APIDoc/ATG/Commerce/pricing/AmountInfo.html#getAdjustments )

    Now browse adjustments, for pricingmodel (i.e. promotion) and coupon applied on order

    PricingAdjustment (ATG Java API)

    PricingAdjustment (ATG Java API)

    Hope that gives you an idea where to start.

    -Kiss

Maybe you are looking for