application of the hierarchy and analytical functions

Hi I have 2 tables that are

TBL ACCOUNT
ACCOUNT_ID        PAYING_ACCOUNT_ID           PARENT_ACCOUNT_ID
4571111               4571111                    4571111   
4571112               4571112                    4571111
4571113               4571113                    4571111
3995313               3995313                    3995313
3996786               3995313                    3995313
4008375               3995313                    3995313
CUSTOMER_STATUS
CUSTOMER_ID        CUSTOMER_STATUS
4571111                Active   
4571112                Active       
4571113                Active       
3995313                Active     
3996786                Deactive       
4008375                Active       
I need to produce an output like below:
Level_Label            ACCOUNT_ID       PAYING_ACCOUNT_ID    PARENT_ACCOUNT_ID    MY_TOTAL_PR_A   MY_TOTAL_NPR_A   TOTAL_PR_A   TOTAL_NPR_A     MY_TOTAL_PR_D       MY_TOTAL_NPR_D      TOTAL_PR_D      TOTAL_NPR_D
3995313                  3995313             3995313              3995313               0            1               0            1                  0                 1                   0               1
      4008375            4008375             3995313              3995313               0            0               0            1                  0                 0                   0               1
      3996786            3996786             3995313              3995313               0            0               0            1                  0                 0                   0               1
4571111                  4571111             4571111              4571111               2            0               2            0                  0                 0                   0               0
      4571112            4571112             4571112              4571111               0            0               2            0                  0                 0                   0               0
      4571113            4571113             4571113              4571111               0            0               2            0                  0                 0                   0               0
It's the logic and rational to fill up over fields.
MY_TOTAL_PR_A            Sum of all child accounts of current account that are PR (PAYING_ACCOUNT_ID = ACCOUNT_ID) and in sates considered Active. 
                                     The current account is not included in the sum, only child accounts

MY_TOTAL_NPR_A          Sum of all child accounts of current account that are NPR (PAYING_ACCOUNT_ID != ACCOUNT_ID)  and in sates considered Active. 
                                     The current account is not included in the sum, only child accounts

TOTAL_PR_A                  Sum of all accounts of the structure that are PR and in sates considered Active. 
                                     The TOP account is not included in the sum, only TOP account childs

TOTAL_NPR_A                Sum of all accounts of the structure that are NPR and in sates considered Active. 
                                     The TOP account is not included in the sum, only TOP account childs


MY_TOTAL_PR_D            Sum of all child accounts of current account that are PR and in sates considered Deactive. 
                                     The current account is not included in the sum, only child accounts


MY_TOTAL_NPR_D          Sum of all child accounts of current account that are NPR and in sates considered Deactive. 
                                      The current account is not included in the sum, only child accounts


TOTAL_PR_D                Sum of all accounts of the structure that are PR and in sates considered Deactive. 
                                      The TOP account is not included in the sum, only TOP account childs


TOTAL_NPR_D              Sum of all accounts of the structure that are NPR and in sates considered Deactive. 
                                       The TOP account is not included in the sum, only TOP account childs
This is my code, I managed to calculate the MY_TOTAL_XXX filed but was unable to calculate TOTAL_XXX. Appreciate any information / comment. Thank you
WITH     got_descendants          AS
(
     SELECT     CONNECT_BY_ROOT a.account_id     AS ancestor_id
     ,     a.paying_account_id
  ,  a.account_id
  , a.parent_account_id
     ,     LEVEL                    AS lvl
  , c.customer_status
     FROM     account a inner join customer_status c
  on a.account_id = c.customer_id
     CONNECT BY NOCYCLE     PRIOR a.account_id     = a.parent_account_id
          --AND          account_id          != parent_account_id
), DUMMY2 AS
(
select g.*  from got_descendants g
), DUMMY AS
(
SELECT       ancestor_id
,       COUNT (CASE WHEN lvl             > 1
                  AND  account_id  = paying_account_id
            And  ancestor_id != account_id
            AND  customer_status = 'A' THEN 1 END)     AS my_total_pr_a
,       COUNT (CASE WHEN ancestor_id  = paying_account_id
           AND  customer_status = 'A' THEN 1 END)     AS total_pr_a
,       COUNT (CASE WHEN lvl             > 1
                  AND  account_id != paying_account_id
            And  ancestor_id != account_id
            AND  customer_status = 'A' THEN 1 END)     AS my_total_npr_a
,       COUNT (CASE WHEN ancestor_id != paying_account_id 
           AND  customer_status = 'A'
           And  ancestor_id != parent_account_id THEN 1 END)     AS total_npr_a
,       COUNT (CASE WHEN lvl             > 1
                  AND  account_id  = paying_account_id
            And  ancestor_id != account_id
            AND  customer_status = 'D' THEN 1 END)     AS my_total_pr_d
,       COUNT (CASE WHEN ancestor_id  = paying_account_id
           AND  customer_status = 'D' THEN 1 END)     AS total_pr_d
,       COUNT (CASE WHEN lvl             > 1
                  AND  account_id != paying_account_id
            And  ancestor_id != account_id
            AND  customer_status = 'D' THEN 1 END)     AS my_total_npr_d
,       COUNT (CASE WHEN ancestor_id != paying_account_id 
           AND  customer_status = 'D' THEN 1 END)     AS total_npr_d
FROM       DUMMY2
GROUP BY ancestor_id
)
SELECT  lpad(' ', 2*level) || ACCOUNT.ACCOUNT_ID AS LEVEL_LABEL, LEVEL, CONNECT_BY_ISCYCLE "Cycle",
ACCOUNT.PAYING_ACCOUNT_ID, ACCOUNT.PARENT_ACCOUNT_ID, ACCOUNT.ACCOUNT_ID,
DUMMY.my_total_pr_a, DUMMY.total_pr_a, DUMMY.my_total_npr_a, DUMMY.total_npr_a,
DUMMY.my_total_pr_d, DUMMY.total_pr_d, DUMMY.my_total_npr_d, DUMMY.total_npr_d
from ACCOUNT INNER JOIN DUMMY  ON  ACCOUNT.account_id = DUMMY.ancestor_id
START WITH ACCOUNT.parent_account_id = ACCOUNT.account_id  
CONNECT BY NOCYCLE PRIOR ACCOUNT.account_id = ACCOUNT.parent_account_id
DDL
CREATE TABLE ACCOUNT
  (
    "CUSTOMER_ID"       NUMBER(20,0) NOT NULL ENABLE,
    "PAYING_ACCOUNT_ID" NUMBER(20,0),
    "PARENT_ACCOUNT_ID" NUMBER(20,0),
    "ACCOUNT_ID"        NUMBER,
    "COMPANY_ID"        NUMBER
  )

CREATE TABLE CUSTOMER_STATUS
  (
    "CUSTOMER_ID"     NUMBER(10,0),
    "CUSTOMER_STATUS" VARCHAR2(1 BYTE)
  )


Insert into ACCOUNT (ACCOUNT_ID,PAYING_ACCOUNT_ID,PARENT_ACCOUNT_ID) values (4571111,4571111,4571111);
Insert into ACCOUNT (ACCOUNT_ID,PAYING_ACCOUNT_ID,PARENT_ACCOUNT_ID) values (4571112,4571112,4571111);
Insert into ACCOUNT (ACCOUNT_ID,PAYING_ACCOUNT_ID,PARENT_ACCOUNT_ID) values (4571113,4571113,4571111);
Insert into ACCOUNT (ACCOUNT_ID,PAYING_ACCOUNT_ID,PARENT_ACCOUNT_ID) values (3996786,3995313,3995313);
Insert into ACCOUNT (ACCOUNT_ID,PAYING_ACCOUNT_ID,PARENT_ACCOUNT_ID) values (4008375,3995313,3995313);
Insert into ACCOUNT (ACCOUNT_ID,PAYING_ACCOUNT_ID,PARENT_ACCOUNT_ID) values (3995313,3995313,3995313);


Insert into CUSTOMER_STATUS (CUSTOMER_ID,CUSTOMER_STATUS) values (3996786,'D');
Insert into CUSTOMER_STATUS (CUSTOMER_ID,CUSTOMER_STATUS) values (4008375,'A');
Insert into CUSTOMER_STATUS (CUSTOMER_ID,CUSTOMER_STATUS) values (3995313,'A');
Insert into CUSTOMER_STATUS (CUSTOMER_ID,CUSTOMER_STATUS) values (4571111,'A');
Insert into CUSTOMER_STATUS (CUSTOMER_ID,CUSTOMER_STATUS) values (4571112,'A');
Insert into CUSTOMER_STATUS (CUSTOMER_ID,CUSTOMER_STATUS) values (4571113,'A');

Hello

user11432758 wrote:
Hi, this is the error msg

ORA-00904: "O_NUM": invalid identifier
00904. 00000 -  "%s: invalid identifier"

The reason for this error is that the only "table" in the query is

...
FROM      dummy
GROUP BY ancestor_id
ORDER BY  MIN (o_num)

but the model has no column named o_num.

I'm still not sure that understand what you want to do.
He gets the results you want from the data sample:

WITH     got_customer_status     AS
(
     SELECT  a.account_id
     ,     a.paying_account_id
       ,     a.parent_account_id
       ,     c.customer_status
     ,     CASE
              WHEN  a.account_id = a.parent_account_id
              THEN  1
          END     AS is_root
     FROM          account          a
     INNER JOIN     customer_status c  ON     a.account_id = c.customer_id
)
,     got_descendants          AS
(
     SELECT     CONNECT_BY_ROOT account_id               AS ancestor_id
     ,     paying_account_id
       ,     account_id
       ,     parent_account_id
     ,     LEVEL                              AS lvl
     ,     (CONNECT_BY_ROOT is_root) * LEVEL          AS rlvl
       ,     customer_status
     ,     is_root
     ,     (CONNECT_BY_ROOT is_root) * ROWNUM          AS rnum
     FROM     got_customer_status
     CONNECT BY      PRIOR account_id     = parent_account_id
          AND     account_id          != parent_account_id
)
,     got_my_totals     AS
(
     SELECT       ancestor_id
     ,       COUNT ( CASE WHEN lvl               > 1
                              AND  account_id          = paying_account_id
                             AND  ancestor_id        != account_id
                             AND  customer_status      = 'A'
                      THEN 1
                  END
               )     AS my_total_pr_a
     ,       COUNT ( CASE WHEN lvl               > 1
                              AND  account_id           != paying_account_id
                                   And  ancestor_id      != account_id
                                   AND  customer_status      = 'A'
                      THEN 1
                  END
               )     AS my_total_npr_a
     ,       COUNT (CASE WHEN lvl             > 1
                  AND  account_id  = paying_account_id
                       And  ancestor_id != account_id
                       AND  customer_status = 'D' THEN 1 END)     AS my_total_pr_d
     ,       COUNT (CASE WHEN lvl             > 1
                  AND  account_id != paying_account_id
                       And  ancestor_id != account_id
                       AND  customer_status = 'D' THEN 1 END)     AS my_total_npr_d
     FROM       got_descendants
     GROUP BY  ancestor_id
)
SELECT    LPAD (' ', 2 * d.rlvl) || d.account_id     AS level_label
,       NVL (d.is_root, 0)                    AS cycle
,       d.paying_account_id
,       d.parent_account_id
,       d.account_id
,       t.my_total_pr_a
,       FIRST_VALUE (my_total_pr_a)  OVER ( PARTITION BY  d.ancestor_id
                                             ORDER BY      d.rnum
                             )              AS total_pr_a
,       t.my_total_npr_a
,       FIRST_VALUE (my_total_npr_a) OVER ( PARTITION BY  d.ancestor_id
                                             ORDER BY          d.rnum
                             )              AS total_pr_a
,       t.my_total_pr_d
,       FIRST_VALUE (my_total_pr_d)  OVER ( PARTITION BY  d.ancestor_id
                                             ORDER BY      d.rnum
                             )              AS total_pr_d
,       t.my_total_npr_d
,       FIRST_VALUE (my_total_npr_d) OVER ( PARTITION BY  d.ancestor_id
                                             ORDER BY          d.rnum
                             )              AS total_pr_d
FROM       got_descendants     d
JOIN       got_my_totals     t  ON     d.account_id     = t.ancestor_id
WHERE       d.rnum     IS NOT NULL
ORDER BY  d.rnum
;

This should be faster than what I've posted before, because there is only one CONNECTION PER request. It avoids join them in the same application that CONNECT BY and does not use NOCYCLE. Once more, visit the forum FAQ {message identifier: = 9360003}

Tags: Database

Similar Questions

  • application of the hierarchy and the number of subnodes

    Hi all

    I've been struggling with this: is it possible to select the number of subnodes of a banch? the only way I can think is:
    select id, desc, (select count(*) from table b connect by prior id=parent_id start with b.parent_id =a.id )
    from table a
    connect by prior id=parent_id
    start with parent_id is null
    order siblings by id
    but I wonder if this is the way to go, or there is a more simple/fast way to do it.

    Thanks in advance for any help! This query is run on Oracle 10 g 2 and upwards!

    Great, thanks for the sample data.

    Here's another approach that uses a single connection by statement.

    select
       the_root,
       the_description,
       count(*) - 1                     as subnodes
    from
    (
       select
          connect_by_root(a.id)            as the_root,
          connect_by_root(a.description)   as the_description
       from
          tab a
       connect by prior id = parent_id
    )
    group by
       the_root,
       the_description
    order by
     18     the_root asc;
    
              THE_ROOT THE_DESCRIPTION                                                                                                SUBNODES
    ------------------ ---------------------------------------------------------------------------------------------------- ------------------
                     1 Main node                                                                                                             7
                     2 Module 1                                                                                                              3
                     3 Module 1 subnode 1                                                                                                    0
                     4 Module 1 subnode 2                                                                                                    0
                     5 Module 1 subnode 3                                                                                                    0
                     6 Module 2                                                                                                              0
                     7 Module 3                                                                                                              1
                     8 Module 3 subnode 1                                                                                                    0
    
    8 rows selected.
    
    Elapsed: 00:00:00.02
    TUBBY_TUBBZ?
    
  • How can I get the date and time function to appear as a tile

    How can I get the date and time function to appear as a tile

    How can I get the date and time function to appear as a tile

    WIN8 are delivered with this tile/app.  The only way to display the time is to launch the charm bar (Win - key + C) or mouse over to the right up/down.  That said go to the Windows store... There are several free applications that display the time / date as a live tile.  Good luck.

  • Just installed Mac OS Sierra on Mac Pro air. What I do need to update to Safari and other applications on the iPhone and I have the carpet?

    Just installed Mac OS Sierra on Mac Pro air.

    What I do need to update to Safari and other applications on the iPhone and I have the carpet?

    Unless otherwise indicated by an application or in the description of an update, no.

    (144880)

  • Run the application in the background and receive updates of geolocation

    Is it possible to run an application in the background (for example all doing other things such as the use of browser, mail, etc) and always receive updates HTML5 geolocation?

    If you make your application in the "background" and do not close, the watchPosition should go on the provision of data within your App App in the background means you open the app and ample bottom to somehow minimize, for example. to open another app or something like that. As long as he remains upwards in the list of open applications it should "look at the position.

  • application on the phone and Tablet

    I have an application with a version for phones. Now I intend to create the application for the Playbook by using the native SDK. I got a new set of key signature for the NDK. So, if the user buy the app for the Playbook or their phone, can they can get for free for the other device? Is buying related to the same app World and do not want to touch the phone and tablet version is signed with?

    Thank you
    NIC

    Basically, you have two options:

    (1) to submit the PlayBook version as a new application

    (2) to present the PlayBook version as a new version of your application for phone

    If you choose option 1) users who have purchased the phone app should buy the app PlayBook too if they want to use it

    If you choose option 2) users who have bought the phone app will be able to download free version of the PlayBook. The reverse is also true - if a user has purchased the PlayBook version, he or she will be able to download free version of phone. It is because the purchases are linked to the BlackBerry ID and most users will use the same ID on PlayBook and phone.

    Option 2) has additional options - all the notes and comments will go to one and the same product. In addition, you will need to adjust the app description if the functionality of these two version is different.

    Signature keys have nothing to do with the Tablet and phone versions, they are pure development.

  • With the help of analytical functions

    Hi all

    I'm using ODI 11 g (11.1.1.3.0) and I'm doing an interface using analytical functions in the column map, something like below.
    Salary on (partition of...)

    The problem is that when ODI saw the sum he considers this an aggregate function and the group. Is it possible to understand that it is not an aggregate in ODI function?


    I tried to create an option to specify whether it is analytic, then updated IKM with no luck.
    < % if (odiRef.getUserExit("ANALYTIC").equals("1")) {% >}
    < %} else {% >}
    < % = odiRef.getGrpBy (i) % >
    < % = odiRef.getHaving (i) % >
    < %} % >

    Thanks in advance

    Seth,

    Try this thing posted by Uli:
    http://www.business-intelligence-quotient.com/?p=905

  • Is it possible to have a common accessible file location for the main application in the sandbox and its extension app plugin

    I'm trying to launch an app on the app store for mac. The bundle of the main application and everything inside it is on sandbox.

    The main application Bundle identifier is com.xxx.core.app . The identifier for the internal Plugin Finder Extension application Bundle is com.xxx.core.app.extensions .

    Now the problem is the extension inner finder is also available in sand and trying to read a file written by the main application.

    The main application writes the file location depending on mac OS X, for example temp/var/folder/jv11743453495593/T/com.xxx.core.app

    But the internal Plugins try to read/var/folder/jv11743453495593/T/com.xxx.core.app/extensions

    Because of the different bundle identifiers, they have different containers.

    Can someone let me know how to limit the same application and its plugins to the same folder location. Does perform a work around for this problem.

    Hello yuktikapahwa,

    See the Sandbox Apple Guide under the ApplicationDirectory group container

    You must create a group that your container can access. I'm not 100% certain that this will work with extensions of Finder, but it seems the most logical place to start.

  • where can I get the application of the excell and writer and pdf reader

    Where can I get reading apps, is calculating as in Mobile Android (pdf etc.)

    Hi marvelouse,.

    Unfortunately, it is not possible to install Android .apk on Firefox OS.

    If, however, the application has a web - app or the mobile version of its Web site available, you can access these services and pin them to your home screen of Firefox for the operating system.

    Alternatively, you can contact the developers and ask that they create a version compatible with Firefox OS and the open Web.

    -Ralph

  • Why my Apple Watch is constantly with the application of the workout and kill my battery

    Since the last Watch 2.0 update my watch is constantly showing the little running man at the top of the watch.  He seems to think that I work constantly and telling me I'm burning crazy amounts of calories (pretty sure he thinks that my train ride is me currently underway).  For not to mention my battery dies quickly.  I started the day at 630 with 100% of battery, the green light on my wrist has served all day and my battery is at 13%.  How can I fix this.  I have not matched the watch and combined with new, but that solves nothing.  Any help would be appreciated since my watch is basically useless at this point.

    Hi Steve

    Green rider icon indicates that your watch has currently underway training.

    You can currently get a workout paused in the application of the workout or a third-party (for example, Strava) fitness application.

    If you have used Strava or any other third-party application, you must put an end to the activity via this application on your watch (not on your iPhone).

  • Error code 80070424 during the application update the window and installing the Apple Application Support

    Hi guys,.

    I am running Windows Vista Premium Home 64 bit. This all started when update me my iTune recently and since then it has been a headache after another. Basically, when I try to install iTune, it says that I need to install Apple Application Support first, and when I do that, I get the following message appears:

    "An error occurred during the installation of assembly"Microsoft.VC80, CRT, Version... ". "and it lights up.

    In addition, I also tried to install Vista SP 2 recently but my window update also gives me a pain. I can't get the update because when I try, it says 80070242 error code - Windows Update encountered an unknown error.

    Here are the pictures of the 2 filters:

    Any help at all would be greatly appreciated.

    Thanks for the suggestion of Augustine, but the problem is still present. The order went through, but I always feel error 80070424 and is possibly due to a malfunction of Windows Installer Module.

    Thanks for the attempt. Appreciate it.

    Suggest you check to see if the Windows Modules Installer service is present, has not been disabled and can be started.
    Right click the computer on the desktop or the Start Menu and choose Manage
    The UAC prompt to enter a password if one is used, then click on continue or Yes.
    If no password is used, click on continue.
    Click the arrow next to Services and Applications
    Click Services in the left frame
    Scroll down the list of Services in the context of e right until you come of Windows Modules Installer .
    If it is present, check under Startup Type to see if it has been disabled.
    The default setting is manual.
    At the top left will be a link to start the service
    Click on it and see if the service can be started.

    If the installer of Modules of Windows is disabled, right click on it and choose Properties .
    Set the startup type to Manual , click on apply, OK.
    Close the computer management console.

    If the Windows Modules Installer is not present and of Flavius are too difficult for you to follow, then replace
    Contact MS Support free of charge.
    Start here
    Make a mark next to "I use it for my own personal use.
    Now click on the button continue.
    Click on the I accept"" button.
    Support options will be displayed. The only option I see here is for email support.
    Click on the button continue to access the support request form.
    Fill in the fields and then click on the button continue.

    MowGreen Services consumer safety update

  • Applications in the games and accessories does not open.

    When I click with the right button on the program, say the painting and choose Properties, she says, they are located in the System32 folder, but they will not even open when I click on them directly. I think that is why my last Windows Update will not install, because this is a security fix for the painting.

    Hello
     
    1. don't you make changes on the computer before the issue started?
    2. this happens with all applications that are located in the games and accessories?
    3 have you tried to launch the program from its target location?
     
    First try to open the program from its location of the target. To know the location of the target and the name of the program, right click on the program item in the start menu, and then click Properties.
    By default, the target location is % windir%\System32.
     
    Try these steps and check the result.
    Step 1: Turn off non-Microsoft programs, and then try to open the start menu applications.
    Follow step 1 to perform a clean boot to disable all non-Microsoft programs: http://support.microsoft.com/kb/929135
    If the problem does not persist in the boot, it means that some programs non-Microsoft is causing this issue. To find out which program is the cause, try step 2 to step 6 to find the culprit: http://support.microsoft.com/kb/929135
    NOTE: Follow step 7 to start the computer in normal mode: http://support.microsoft.com/kb/929135
     
    Step 2: Sfc scanner to fix corrupted system files.
    1. open an elevated command prompt. To do this, click Start, click programs, accessories principally made, right-click Guest, and then click Run as administrator. If you are prompted for an administrator password or a confirmation, type the password, or click on allow.
    2. type the following command and press ENTER: sfc/scannow
     
    The sfc/scannow command. analyzes all protected system files and replaces incorrect versions with appropriate Microsoft versions.
    For more information, see this link: http://support.microsoft.com/kb/929833
     
    I hope this helps.
    Post back with the results, so that we can help you further.
     
    Kind regards
    Syed
    Answers from Microsoft supports the engineer.
    Visit our Microsoft answers feedback Forum and let us know what you think.

  • Allowing entry of the value of a property at the level of the hierarchy and restricting to whole new level.

    Hi all

    I have two property definition Custom.Levelnumber and Custom.Allowattribute which are the goods as well as Local property node level.

    I want validation to restrict the user to allow any value for the Custom.Allowattribute property for any level of hierarchy other than level 6 i, e Custom.Levelnumber with the value 6.

    all other classes in the hierarchy must have an empty value for the Custom.Allowattribute property.

    Hi Madhu,

    Try this-

    If)

    Not (Equals (Integer, PropValue (Custom.LevelNumber), 6));

    Not (IsDefinedPropVal (Custom.Allowattribute, ABBREV (())).

    True)

  • Applications of the muse and earlier versions (cs6)

    Hello

    I'm looking into buying Muse, but I fear that installing a CC application will affect my apps CS6, mainly photoshop, illustrator and indesign.

    I would setup the the whole outfit of CC but I can't we afford it right now. Could someone let me know if there will be problems with Muse CC or CS6 applications running? Thank you

    Concerning

    Nathan

    There is absolutely no problem with the help of CS6 applications at the same time to Adobe Muse CC. Let us know if there is a reason for your concerns.

  • Application of the hierarchy

    Hello

    I need to get back to Manager user for each hier_id id in the hier_users table. If the hier_id not record in the hier_users table, you must submit parent hier_id Manager user_id. my output should be like this. I need to do this by using SQL.

    user_id hier_id

    1 101

    2 100

    3 102

    4 100 -this hierarchy is not the Manager save both need to return its parent hierarchy 2 Manager user_id



     CREATE TABLE hier (ch_id NUMBER(18), pa_id NUMBER(18))
     /
     CREATE TABLE hier_users (user_id NUMBER(18) , ch_id NUMBER(18), role VARCHAR2(20))
     /
     INSERT INTO hier VALUES (1 , NULL)
     /
     INSERT INTO hier VALUES (2 , 1)
     /
     INSERT INTO hier VALUES (3 , 1)
     /
     INSERT INTO hier VALUES (4 , 2)
     /
     INSERT INTO hier_users VALUES (100 , 2,'manager')
     /
     INSERT INTO hier_users VALUES (101 , 1, 'manager')
     /
     INSERT INTO hier_users VALUES (102 , 3, 'manager')
     /
     INSERT INTO hier_users VALUES (103 , 4, 'member')
     /
    

    Thanks in advance

    What of it?

    Is to find the first manager in the hierarchy

    SELECT a.ch_id
         , ( SELECT c.user_id
               FROM hier_users c, hier b
              WHERE c.ch_id = b.ch_id AND role = 'manager' AND ROWNUM <= 1
            CONNECT BY PRIOR b.pa_id = b.ch_id
            START WITH b.ch_id = a.ch_id
           ) user_id
      FROM hier_users a;
    

    Output will be like:

    USER_ID CH_ID

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

    2 101

    1 101

    3 102

    4 101

    Kind regards.

    Al

Maybe you are looking for

  • A lot of problems with Web site. May be the problem of Java.

    I'll try to give as much detail as possible.1. a few youtube videos will not play.2 thumbnails will not appear.3Facebook does not load. All I get is the top tool bar. Can't see newsfeed, messages etc.4 Omegle doesn't work.5. on the reddit Web site, I

  • Pavilion g6 turned off and will not turn back on

    My g6 kept turning off unexpectedly, and now it will not even turn around.  Help, please.

  • F4200 HP printer prints only 1 color page correctly

    You have a strange problem with my all in one printer F4200. Bought a new (good ink HP) ink cartridge Since then, whenever I try to print more than 1 page colors after the 1st page crazy sometimes printing red sometimes yellow etc. ' (1st page colors

  • You can survey objects to see if the class data were populated in a child method?

    Question, If a parent method is cast down to the child class, and then a method is used to update some data in the class data, that the data is visible with a probe on the wire coming from the object? Or is the data view of the data in the parent cla

  • Use Schedule Auto dynamic locking

    Hello The configuration is the following: My client wants to run 4 devices of individual test on the same PC. Each test set-up will take place at least 4 parallel trials at the same time by using the parallel model. For now, let's assume it's the sam