Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

hierarchical query inheritance

Igor S.May 5 2017 — edited May 11 2017

Dear Oracle Pros,

I need a help with a query where you pass a value from parent to child, but only if the child has no value of his. I am trying to go from value column to end_result column:

Sample

with x as

       (select 1 as id

              ,null as parent

              ,1 as value

              ,1 as end_result

          from dual

        union

        select 2

              ,1

              ,0

              ,0

          from dual

        union

        select 3

              ,1

              ,null

              ,1

          from dual

        union

        select 4

              ,2

              ,0

              ,0

          from dual

        union

        select 5

              ,2

              ,1

              ,1

          from dual

        union

        select 6

              ,2

              ,null

              ,0

          from dual

        union

        select 7

              ,3

              ,null

              ,1

          from dual

        union

        select 8

              ,3

              ,null

              ,1

          from dual

        union

        select 9

              ,3

              ,null

              ,1

          from dual)

  select x.*

    from x

order by id, parent;

This post has been answered by Anton Scheffer on May 5 2017
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 8 2017
Added on May 5 2017
5 comments
389 views