Query to find the hierarchy with the siblings without parent location data

I have an IDDDETAILS table

CREATE TABLE IDDETAILS

(NUMBER OF GRPID,

IDNO NUMBER,

NUMBER OF THIERRY,

IDDESC VARCHAR2 (100),

PHONE NUMBER

);

Insert into IDDETAILS

(GRPID, IDNO, IDDESC, CONTACT)

Values

(1001, ' 1, parent entry ', 9820);

Insert into IDDETAILS

(GRPID, IDNO, THIERRY, IDDESC, CONTACT)

Values

(1001, 2, 1, "first ent", 9920);

Insert into IDDETAILS

(GRPID, IDNO, THIERRY, IDDESC, CONTACT)

Values

(1001, 3, 1, 'second', 9120);

Insert into IDDETAILS

(GRPID, IDNO, THIERRY, IDDESC, CONTACT)

Values

(1001, 4, 2, 'third', 9220);

Insert into IDDETAILS

(GRPID, IDNO, IDDESC, CONTACT)

Values

(1001, 5, 'five', 9230);

Insert into IDDETAILS

(GRPID, IDNO, THIERRY, IDDESC, CONTACT)

Values

(1001, 6, 5, "six", 9234);

Insert into IDDETAILS

(GRPID, IDNO, THIERRY, IDDESC, CONTACT)

Values

(1001, 7, 6, 'seven', 9237);

Insert into IDDETAILS

(GRPID, IDNO, THIERRY, IDDESC, CONTACT)

Values

(1001, 8, 5, 'eight', 9238);

COMMIT;

If I pass the contact as 9220, so I need the entries for these contact 9920 correspondent and Thierry shares same and here documents pard Thierry even values and records in the table. It is upto Thierry is null

Example of result

Contact 9920

grpid idno Thierry

1001 1 null

1001 2 1

1001 3 1

1001 4 2

Conatct no 9238

grpid idno Thierry

1001 5 null

1001 6 5

1001 8 5

Please please help to solve

Hello

Thanks for posting the CREATE TABLE and INSERT statements; It's very useful!

When you pass 9220, you want to get 9120, which relates to 9220, but is not an ancestor of 9220.

When you pass 9238, why you don't want 9237?

In the title, you said something about brothers and sisters, then maybe you want to the ancestors of the contact you spend (in other words, the parent and the parent the parent and parent of the line and so on) and the brothers and sisters of the line of target or any ancestors (in other words, rows that have the same parent).  For example, when the contact spent is 9238 (idno = 8) then you want all his ancestors (idno = 5 is the single ancestor) and also the brothers and sisters of all lines already included (idno = 6 is an idno subling = 8, as they have all two Thierry = 5).  IDNo = 7 is not included, because it is not contact with the target, an ancestor of the target contact, or a brother.  If this is what you want, then:

WITH the ancestors AS

(

SELECT grpid, idno, Thierry

Of iddetails

START WITH contact = limited to 9 238 - or any contact you want

CONNECTION BY idno = Thierry PREREQUISITE

)

SELECT *.

Ancestors

UNION

SELECT grpid, idno, Thierry

Of iddetails

(IN) WHERE Thierry

SELECT Thierry

Ancestors

)

;

Output:

GRPID IDNO THIERRY

------- ------- -------

1001 5

1001 6 5

1001 8 5

However, in the title you also said that "without parent location.  The above query (and your results) include idno = 5.  If idno = 5 is not "located" idno parent = 8, then what does 'parent located?

Tags: Database

Similar Questions

  • Query to find the Pages and the list of permissions associated with a particular role in PS

    I want a query to find the Pages and the list of permissions associated with specific roles in PS.

    For example, if we see the role of manager accounts payable, it conatins Pages and the list of permissions.

    But, to get everything in EXCEL sheet by Manuel priocess's BIG job. So, can someone give me the query.

    Please try under queries

    The roles assigned to the list of Perm:

    SELECT B.ROLENAME

    OF PSCLASSDEFN A, PSROLECLASS B

    WHERE (A.CLASSID = B.CLASSID

    AND A.CLASSID =: 1).

    List of Perm pages can access:

    SELECT B.MENUNAME, B.BARNAME, B.BARITEMNAME, B.PNLITEMNAME, C.PAGEACCESSDESCR, B.DISPLAYONLY

    OF PSCLASSDEFN A, PSAUTHITEM B, PSPGEACCESSDESC C

    WHERE (A.CLASSID = B.CLASSID

    AND A.CLASSID =: 1

    AND B.BARITEMNAME > ' '

    AND B.AUTHORIZEDACTIONS = C.AUTHORIZEDACTIONS)

  • What is the query to find the name of all applications for all EBS R12.1.3 modules?

    What is the query to find the name of all applications for all EBS R12.1.3 modules?

    With regard to:

    Mr. Shahzad Saleem

    Try:

    SELECT * FROM fnd_concurrent_programs_vl;

  • SQL query to find the total number of source based nonsource passangersbetween source and destination station and passenger station on the same chekindate

    Hello

    SQL query to find the total number of source based nonsource passangersbetween source and destination station and passenger station on the same chekindate.

    Please help on this script and let me know if you need more details.

    ---

    You use a SELECT statement.  Let me know if you need more details.

  • query to find the dependent task, attached to the task on a response in OIM 11 g

    can someone help me to do a sql query to find the dependent task, attached to the task on a response in OIM 11 g

    Published by: user13331347 on Sep 3, 2012 14:09

    Use under query to find the dependent task in OIM 11 g: -.

    Select pkg.pkg_name, mil.mil_name, rsc.rsc_data, rsc.sta_key, sta.sta_status, sta.sta_bucket, mil2.mil_name
    pkg pkg, tos tos, mil mil, mil mil2, rsc rsc, sta sta, rgm the rgm
    where pkg.pkg_key = tos.pkg_key
    and tos.tos_key = mil.tos_key
    and mil.mil_key = rsc.mil_key
    and rsc.sta_key = sta.sta_key
    and rgm.rsc_key = rsc.rsc_key
    and rgm.mil_key = mil2.mil_key
    order of pkg.pkg_name, mil.mil_name, rsc.rsc_data, sta.sta_status, mil2.mil_name

  • Query to find the coordinates of employee salary

    Hello

    Could someone help write the query to find the salary of the employee details.

    Thanks in advance.

    This should help you get started:

    SELECT papf.full_name
    papf.email_address
    ppp.proposed_salary_n salary
    OF per_pay_proposals ppp
    per_all_assignments_f ADP
    per_all_people_f women's wear
    WHERE ppp.assignment_id = paaf.assignment_id
    AND paaf.assignment_type = 'E '.
    AND paaf.primary_flag = 'Y '.
    AND paaf.person_id = papf.person_id
    AND nvl (papf.current_employee_flag, 'n') = 'Y '.
    AND trunc (sysdate) BETWEEN
    PPP.change_date AND ppp.date_to
    AND trunc (sysdate) BETWEEN
    PAAF.effective_start_date AND paaf.effective_end_date
    AND trunc (sysdate) BETWEEN
    PAPF.effective_start_date AND papf.effective_end_date;

  • To find the Top most parent SQL

    How to find the top most parent SQL. I want to avoid the hierarchical query that shows a high cost to run. Please suggest alternative options to find the parent

    Maybe (when having multiple hierarchy trees) to be adapted to your needs

    Select empno, I

    from (select empno, I

    WCP

    where empno = 7876

    model

    hierarchy of reference on (select employee empno,

    Manager Mgr

    WCP

    )

    dimension (employee)

    measures (Manager)

    main main_model

    size of (0 I)

    measures (empno)

    rules iterate (100) until (empno [iteration_number + 1] is null)

    (

    EmpNo [iteration_number + 1] = hierarchy.manager [empno [iteration_number]]

    )

    )

    where empno is not null

    order by I desc

    EMPNO I
    7839 3
    7566 2
    7788 1
    7876 0

    Concerning

    Etbin

  • Query to find the previous activity in STM

    I have a data base to reflect a State of Transition (STM) Machine. It contains 3 tables: activity, node, and Transition.

    Tables of knots and Transition are the configuration of the STM. They define the different possible States and the possible transitions between States.

    The way that I take through the STM is recorded in the activity Table. A record is created for each visited node.

    I need a query that uses the id of my current activity to find my previous activity, i.e. the activity that precedes me directly. The following rules apply:
    -My Id is meaningless
    -It should work for different configurations of the transition and the node tables, but:
    -The starting node is always the node "A".
    -There is no recursive transition, for example ('B', 'B');
    -There is no circular transitions, for example ('B', 'C') and ('C', 'B')
    -Transition and node tables will never change between the creation of the first activity and the execution of the query.
    -The path reflected in the activity table is always a valid path.
    -My current activity is always the last activity.

    For all data below, find the previous activity of activity with id = 4. The correct answer is "C".
    DROP TABLE Transition;
    DROP TABLE Activity;
    DROP TABLE Node;
    
    CREATE TABLE Node
    (
         Id VARCHAR2(1) PRIMARY KEY
    );
    
    CREATE TABLE Activity
    (
         Id Number(8,0) PRIMARY KEY,
         Node_Id VARCHAR2(1)
    );
    
    CREATE TABLE Transition
    (
         FromNode_Id VARCHAR2(1),
         ToNode_Id VARCHAR2(1)
    );
    
    ALTER TABLE Activity
    ADD FOREIGN KEY
    (Node_Id) REFERENCES Node(Id);
    
    ALTER TABLE Transition
    ADD FOREIGN KEY
    (FromNode_Id) REFERENCES Node(Id);
    
    ALTER TABLE Transition
    ADD FOREIGN KEY
    (ToNode_Id) REFERENCES Node(Id);
    
    INSERT INTO Node VALUES ('A');
    INSERT INTO Node VALUES ('B');
    INSERT INTO Node VALUES ('C');
    INSERT INTO Node VALUES ('D');
    
    INSERT INTO Transition VALUES ('A','B');
    INSERT INTO Transition VALUES ('B','C');
    INSERT INTO Transition VALUES ('B','D');
    INSERT INTO Transition VALUES ('C','D');
    
    INSERT INTO Activity VALUES (1,'A');
    INSERT INTO Activity VALUES (2,'B');
    INSERT INTO Activity VALUES (3,'C');
    INSERT INTO Activity VALUES (4,'D');
    Desired output:
    ID
    -
    C

    Hello

    Assuming that all Activity_id tells us nothing on the way, but all lines of activity together to form a single path, we can get results this way:

    WITH     all_paths    AS
    (
         SELECT     'A' || SYS_CONNECT_BY_PATH (a.Node_id, '/')
                  || '/'     AS node_id_path
         FROM     Transition  t
         JOIN     Activity    a  ON  a.Node_Id  = t.ToNode_Id
         WHERE     LEVEL             = (
                                SELECT  COUNT (*)
                             FROM     activity
                             ) - 1
         START WITH  t.FromNode_Id  = 'A'
         CONNECT BY  t.FromNode_Id  = PRIOR t.ToNode_Id
    )
    SELECT       REGEXP_SUBSTR ( node_id_path
                     , '([^/]+)/' || (
                                        SELECT  Node_Id
                                 FROM    activity
                                 WHERE   Id     = 4  -- target_id
                                    )
                             || '/'
                   , 1
                   , 1
                   , NULL
                   , 1
                   )     AS prev_id
    FROM       all_paths
    ;
    

    This means, there is some character (I used "/" above) that we know never appears in Activity.Node_Id.

    Since there are no loops in Transition, it cannot be more than 1 way that involves all activity lines. If there are N lines in operation, this full path will be one that extends to LEVEL = N - 1. (It is not N, N - 1, because the join between the activity and the Transition will always leave 1 line in activity with Node_Id = 'A'). As soon as we have the full path (which is node_id_path in 1 row, produced by all_paths), we just need to guess what was the Node_Id, which corresponds to the id of the target (4 in this example) and find the previous of the delimited node_id_path node_id.

  • Query to find the setting and add it to the minimum value

    Hi, I need a query to run under operation
    I have a table as shown below

    chg tax code Bill rec_no r_cost d_cost
    12345 1 114,35 100.30 1.00 1.00 234
    2 12345 114,35 2.00 1.00 1.00 201
    3 12345 114,35 14.00 1.00 1.00 600
    4 23412 120.90 110,40 1.00 1.05 700
    5 23412 120.90 12,50 1.00 1.05 900


    In this table, I need to find the setting for each rec_no as
    (r_cost + chg + taxes)-sum (d_cost) for rec_no = 12345
    (114.35 + 1.00 1.00)-(100.30+2.00+14.00) plus 0.05
    This 0.05 must be added to the minimum (code) for the rec_no 12345.
    If the d_cost of the code, with rec_no = 12345 201 should be (2.00 + 0.05 = 2.05).

    and,
    (120.90 + 1.00 1.05)-(110.40+12.50) plus 0.05
    This 0.05 must be added to the minimum (code) for the rec_no 23412.
    If the d_cost of the code, with rec_no = 23412 700 should be (110,40 + 0.05 = 110.45).

    Kindly help me in writing of an oracle application to perform the above operation.
     with tab as (
        select 1 invoice,12345 rec_no,114.35 r_cost,100.30 d_cost,1.00 chg,1.00 tax,234 code from dual union all
        select 2 invoice,12345 rec_no,114.35 r_cost,2.00 d_cost,1.00 chg,1.00 tax,201 code from dual union all
        select 3 invoice,12345 rec_no,114.35 r_cost,14.00 d_cost,1.00 chg,1.00 tax,600 code from dual union all
        select 4 invoice,23412 rec_no,120.90 r_cost,110.40 d_cost,1.00 chg,1.05 tax,700 code from dual union all
        select 5 invoice,23412 rec_no,120.90 r_cost,12.50 d_cost,1.00 chg,1.05 tax,900 code from dual
    )
     SELECT tab.*,
      CASE
        WHEN DENSE_RANK() OVER (partition BY rec_no ORDER BY code)=1
        THEN r_cost + chg +tax-SUM(d_cost) over (partition BY rec_no)+MIN(d_cost) keep (DENSE_RANK FIRST
       ORDER BY code) over (partition BY rec_no)
        ELSE d_cost
      END adj
       FROM tab
    ORDER BY invoice
    

    Find out what...

    Ravi Kumar

  • query to find the number of dates

    Hi all

    I need assistance in creating a query. Ask the details I have given below.

    Table:

    Create the table emp_record (emp_id number, emp_join_date date);

    insert into emp_record values (1, 1 June 14 ');

    insert into emp_record values (2, 26 May 14 ');

    insert into emp_record values (3, 16 May 14 ');

    insert into emp_record values (4, 14 May 14 ');

    Suppose I ran the query with sysdate, we need to subtract the date of sysdate, then a report should be prepared in function number how many have subtracted values sysdate below 0 to 3 days, 3-6 date.

    Output should be like

    0 - 3 3-6 6-9 days more than 9 days

    1              0             1                    2

    Please help to write this query. Thank you

    Hello

    Do not essentially repeat the same CASE expression with the same types of calculations for each column.  You can do the job with a CASE expression, like this:

    WITH got_group_id AS

    (

    SELECT THE CHECK BOX

    WHEN emp_join_date< trunc="" (sysdate)="" -="" 8 ="" then ="">

    WHEN emp_join_date< trunc="" (sysdate)="" -="" 5 ="" then ="">

    WHEN emp_join_date< trunc="" (sysdate)="" -="" 2 ="" then ="">

    0 OTHERWISE

    Group_id END AS

    Of emp_record

    WHERE emp_join_date<= sysdate ="" --="" if="">

    )

    SELECT *.

    OF got_group_id

    PIVOT (COUNT (*)

    FOR group_id IN (0 '0-2 days'

    , 3 AS a "3-5 days.

    6 as a "6-8 days"

    , 9 as "9 or more days.

    )

    )

    ;

    It will be much easier to maintain when needs change.

    ED mentioned, using a string, 1 June 14 ' in a place where we expect a date is just a matter of trouble.  2-digit years are too.

  • Query to find the name of the partition

    Hi all

    I'm a little surprised to see that it is not a column I can use to query the name of the partition for a table, in the case of partition of Internval per day...

    I'm looking for a simple query find the name of the partition for the word partition of today ' today... Am I missing something?

    Ask something like...

    Select nom_partition from dba_Tab_partitions where table_name = 'XYZ' and TO_DATE(HIGH_VALUE,'DD-MON-YYYY') = April 2, 2014"

    High value being a long column, lets you convert CHAR or DATE?

    Thanks in advance

    Then, you create a copy of dba_tab_partitions, since you can only convert the LONG data during an insertion type or create the table.

    From Dan article: «just...» If you have a LONG, and you want to appear more than it, you must use TO_LOB to convert it during either an INSERT INTO

    or a CREATE TABLE As . Everything else is just wasting time. "

  • Query to find the sales order

    Hi all
    I need a query to find sales order number against which a serial number is processed.

    Can ny helps an onthis.

    Thank you

    Hello
    Try the following question

    Select wdd.source_document_number
    Of wsn wsh_serial_NUMBERS,.
    wsh_delivery_details JMD
    Where wsn.delivery_detail_id = wdd.delivery_detail_id
    And & wsn.fm_serial_number series
    and nvl (wsn.ti_serial_number, wsn.fm_serial_number)

    Thank you
    Claire

  • Query to find the nth highest salary...

    Hi guys,.

    I can't understand this query that we got a Web site. It is used to find the nth highest salary of the employee... Can someone explain to me please each and every part of it...

    The Charly is:

    Select distinct (a.salary)
    EMP a
    where 1 = (select count (distinct (salary))
    b emp
    where a.salary < = b.salary)

    The "BOLD" part which is the return value... is my main question about this query...

    Help, please

    It is called a correlated sub query. The inner query is executed for each iteration of the outer query. For example, if the table emp has 14 rows and then for each salary 14 the inner query will run.
    The part

    select count(distinct(sal))
    from emp b
    where a.sal<=b.sal
    

    actually counts the number of treatments that are less than or equal to the treatment of the outer query.
    Clearly for the King, who gets the highest salary is greater than or equal to 1 (himself). It returns the highest salary.

    SQL> select *
      2  from emp a
      3  where 1 >= (select count(distinct(sal))
      4  from emp b
      5  where a.sal<=b.sal)
      6  order by sal desc;
    
         EMPNO ENAME                               JOB              MGR HIREDATE         SAL       COMM     DEPTNO
    ---------- ----------------------------------- --------- ---------- --------- ---------- ---------- ----------
          7839 KING                                PRESIDENT            17-NOV-81       5000                    10
    

    Salary of the first two.

    SQL> ed
    Wrote file afiedt.buf
    
      1  select *
      2  from emp a
      3  where 2 >= (select count(distinct(sal))
      4  from emp b
      5  where a.sal<=b.sal)
      6* order by sal desc
    SQL> /
    
         EMPNO ENAME                               JOB              MGR HIREDATE         SAL       COMM     DEPTNO
    ---------- ----------------------------------- --------- ---------- --------- ---------- ---------- ----------
          7839 KING                                PRESIDENT            17-NOV-81       5000                    10
          7902 FORD                                ANALYST         7566 03-DEC-81       3000                    20
          7788 SCOTT                               ANALYST         7566 09-DEC-82       3000                    20
    
  • Query to find the group name for the Business of the employee

    Hello

    I'm new to the HRMS module.

    I want to find employee (per_all_people_f) information about commercial groups.

    I found a HR_ALL_ORGANIZATION_UNITS database table, but there are many records in this table with the same business_group_id that in itself is not a unique key.

    Could someone help me find the link between employees and their BG.

    Thank you.

    Hello

    The link is between per_all_people_f.business_group_id and hr_all_organization_units.organization_id (i.e., the pharmacokinetics of the table). It will be useful.

    Kind regards.

  • Query to find the location

    Hello

    How can I find which location has been selected at the time of patching
    is there any query and a front end method to find the same
    It's about the HRMS patches


    Thank you

    .

    Hello

    Please see the following documents (including the reference documents).

    Note: 269705.1 - Question about prerequisite HRGlobal Patch
    How can note: 269286.1 - I find the Version of human resources (HR) on my system?

    Kind regards
    Hussein

Maybe you are looking for