How to write a query for the following scenario

Hi I have a table as follows which have values of column as below
column1     column2     column3     column4     column5     column6     column7     column8
10000     10     1     7     15     10     9     0
10001     11     2     7     19     0     8     1
10002     12     3     9     8     7     15     0
I want to find the values 7 and 15 on each line together in one of the columns of 4 to 8.

Here, in case I get a first and third ranks.

(Column1, Column2, Column3) is the primary key for the table

Help, please

Hena
with data as
(
select 10000 as column1,     10 as column2,     1 as column3,     7 as column4,     15 as column5,     10 as column6,     9 as column7,     0 as column8 from dual union all
select 10001,     11,     2,     7,     19,     0,     8,     1 from dual union all
select 10002,     12,     3,     9,     8,     7,     15,     0 from dual
)
select * from data
where 7 in (column4, column5, column6, column7, column8)
and   15 in (column4, column5, column6, column7, column8)
/
COLUMN1                COLUMN2                COLUMN3                COLUMN4                COLUMN5                COLUMN6                COLUMN7                COLUMN8
---------------------- ---------------------- ---------------------- ---------------------- ---------------------- ---------------------- ---------------------- ----------------------
10000                  10                     1                      7                      15                     10                     9                      0
10002                  12                     3                      9                      8                      7                      15                     0                      

Edited because requirement changed while displaying the solution

Published by: Cyn on October 30, 2009 15:27

Tags: Database

Similar Questions

  • How to write a query for the given scenario?

    Hi all

    I have two tables EMP, DEPT with data below.
    EMP TABLE: -.
    SAL DEPID EMPLOYMENT ENAME EID
    111 RAM 1500 10 MANAGER
    222 SAM ASST MANAGER 2000 20
    KALA 333 2500 10 REGISTRAR
    444. BIMA 20 3000 MANAGER
    CHALA 555 MANAGER 3500 30
    RANI 666 ASST MANAGER 4000 10
    777 KAMAL MANAGER 2400 10

    DEPT TABLE: -.

    DEPID DNAME
    XX 10
    AA 20
    30 ZZ

    Q1: I want the sum of the salary of each Department and for the particular job. Here, in each Department manager, Assistant Manager, clerk positions are there.
    I want to display the result as below...
    10-20-30 JOBS
    --------------------------------------------------------------------------
    MANAGER OF 3900 3000 3500
    ASST MANAGER 4000 2000 NULL
    THE CLERK 2500 NULL NULL

    Please tell me how to write a sql query?

    Thank you
    SAI
    SQL> SELECT job,
      2         MAX(DECODE(deptno, 10, sum_sal)) "10",
      3         MAX(DECODE(deptno, 20, sum_sal)) "20",
      4         MAX(DECODE(deptno, 30, sum_sal)) "30"
      5  FROM (SELECT deptno, job, SUM(sal) sum_sal FROM emp GROUP BY deptno, job)
      6   GROUP BY job;
    
    JOB               10         20         30
    --------- ---------- ---------- ----------
    CLERK           1300       1900        950
    SALESMAN                              5600
    PRESIDENT       5000
    MANAGER         2450       2975       2850
    ANALYST                    6000
    
    SQL> 
    
  • How to write a query for the data exchange between two columns?

    How to write a query for the data exchange between two columns?

    I tried a request, does NOT work.
    update tmp t1 set t1.m1=t1.m2 and t1.m2=(select t2.m1 from tmp t2 where t2.student_id = t1.student_id)
    Thank you.

    Published by: user533361 on October 23, 2009 14:04

    Just plain and simple:

    update tmp t1
     set t1.m1=t1.m2,
         t1.m2=t1.m1
    /
    

    SY.

  • How to write this query in the hierarchy

    Hi gurus,

    Really need your help on this query.  Thank you very much in advance.

    SELECT
      t1.key as root_key ,
    (SELECT
          t2.unit_id AS unit_id 
          level-1 AS level ,
          t2.name,
          t2.creator
        FROM
          tab t2
          START WITH t2.unit_id       =   t1.unit_id            -----check each node as root
          CONNECT BY prior t2.unit_id = t2.parent_unit_id
    
      )
       t1.name as parent_unit_name
    FROM
      tab t1
    

    I'll write a query of the hierarchy as above, and that EACH line (node, totally more than 10200) is checked as root node to see how many sheets are accessible for her... It must be implemented in a single query.

    I know inline query should NOT return multiple rows or multiple columns, but the inline elements are necessary and can certainly be made in a correct solution.

    (env):

    Database Oracle 12 c Enterprise Edition Release 12.1.0.2.0 - 64 bit Production

    PL/SQL Release 12.1.0.2.0

    )

    Test data:

    select 1 as unit_id, null as parent_organization_unit_id, 'U1' as name from dual
    union all
    select 2, 1, 'U2' FROM DUAL
    UNION ALL
    SELECT 3, NULL, 'U3' FROM DUAL
    UNION ALL
    SELECT 4, 3, 'U4' FROM DUAL
    UNION ALL
    SELECT 5, 2, 'U5' FROM DUAL
    UNION ALL
    SELECT 6, 5, 'U6' FROM DUAL
    UNION ALL
    SELECT 7, 6, 'U7' FROM DUAL
    UNION ALL
    SELECT 8, 5, 'U8' FROM DUAL
    UNION ALL
    SELECT 9, 5, 'U9' FROM DUAL;
    

    Final result should be like this

    key unit_id,    level,   name, parent_name
    1    1    0    u1      u1
    1    2    1    u2       u1
    1    5    2     u5      u1
    1    6    3     u6      u1
    1    7    4    u7       u1
    1    8    3    u8       u1
    1    9    3     u9      u1
    2    2    0     u2       u2
    2    5    1      u5       u2
    2    6    2     u6       u2
    2    7    3      u7      u2
    2    8    2      u8       u2
    2    9    2      u9       u2
    
    

    Don't know how get you your output, it does not match your data...

    with tab as)

    Select 1 as unit_id, null as parent_organization_unit_id 'U1' as the name of double

    Union of all the

    Select 2, 1, 'U2' FROM DUAL

    UNION ALL

    SELECT 3, NULL, 'U3' FROM DUAL

    UNION ALL

    SELECT 4, 3, 'U4' FROM DUAL

    UNION ALL

    SELECT 5, 2, 'U5' OF THE DOUBLE

    UNION ALL

    SELECT 6, 5, 'U6' OF THE DOUBLE

    UNION ALL

    SELECT 7, 6, "U7" OF THE DOUBLE

    UNION ALL

    SELECT 8, 5, 'U8' FROM DUAL

    UNION ALL

    9. SELECT, 5, 'U9' FROM DUAL

    )

    Select dense_rank() key (order by connect_by_root unit_id), unit_id, level - 1 as 'LEVEL', connect_by_root name root_parent_name

    t tab

    Start with parent_organization_unit_id is null

    Connect prior unit_id = parent_organization_unit_id

    KEY UNIT_ID LEVEL ROOT_PARENT_NAME
    1 1 0 "U1".
    1 2 1 "U1".
    1 5 2 "U1".
    1 6 3 "U1".
    1 7 4 "U1".
    1 8 3 "U1".
    1 9 3 "U1".
    2 3 0 "U3".
    2 4 1 "U3".
  • How to write a query for having given the order number

    Hello

    We use 10 gr 2:

    I have data in the following format, I want to group_nr based on month_nr (and it may start from any month)

    month_nr group_nr

    4                    1

    4                    1

    5                    2

    5                    2

    5                    2

    5                    2

    5                    2

    6                    3

    6                    3

    6                    3

    ....

    Thank you

    Select month_nr,

    DENSE_RANK() over (order by month_nr) group_nr

    FROM MyTable

    ----

    Ramin Hashimzade

  • How to plan the failover for the following scenarios in Flex-connect mode.

    The following queries are against the AP high availability (no SSO failover or controller HA), which means that if a controller fails, the AP will be failover to the secondary controller that is in a different location than Geo. the AP will be to connect Flex with local switching and local authorization mode: in this scenario, here are my questions

    1: if I have a SSID that has a set of interfaces that are connected to him, can I switch it on the other controller where there may be a single WLAN connected. ?

    2:do, we need to subnet masks to match both ends?

    3: if I have a SSID with open authentication, can I configure the SSID of the remote network without authentication?

    4: can someone link me to the top with a document that explains the configuration of the case study of the flex-connect mode fail on scenarios.

    Any help given would be really appreciated.

    Thank you.

    1: if I have a SSID that has a set of interfaces that are connected to him, can I switch it on the other controller where there may be a single WLAN connected. ?

    The groups interface works only for centrally switch not locally

    2:do, we need to subnet masks to match both ends?

    See #1

    3: if I have a SSID with open authentication, can I configure the SSID of the remote network without authentication?

    If you configure an SSID with open authentication, then the all having APs SSID assigned to it will use.  Open authentication is identical to no authentication.

    4: can someone link me to the top with a document that explains the configuration of the case study of the flex-connect mode fail on scenarios.

    Do a search on Google for 'FlexConnect deployment guide It will have links to failover.

    -Scott

  • How to write a query for this data?

    In this table, I dob column that is of type DATE, for example, 12 January 89 I want output like this

    Day of the year

    January 12, 89 Thusrs_day

    January 12, 90 Friday

    up to

    12 January 14 Sunday

    Select add_months (d, ((level*12)-12)), to_char (add_months (d, ((level*12)-12)), 'DY')

    de)

    Select d double to_date('12-jan-89','dd-mon-rr')

    )

    connect by level<=>

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

    12.01.1989 GAME

    12.01.1990 FRI

    12.01.1991 SAT

    12.01.1992 SUN

    12.01.1993 MAR

    12.01.1994 SEA

    12.01.1995 GAME

    12.01.1996 FRI

    12.01.1997 SUN

    12.01.1998 LUN

    MAR 12.01.1999

    12.01.2000 SEA

    12.01.2001 FRI

    12.01.2002 SAM

    12.01.2003 SUN

    12.01.2004 LUN

    12.01.2005 WED

    12.01.2006 GAME

    12.01.2007 FRI

    SAM 12.01.2008

    12.01.2009 LUN

    12.01.2010 MAR

    12.01.2011 WED

    12.01.2012 GAME

    24 selected lines

    ----

    Ramin Hashimzade

  • What are the options for assessment 8 Captivate for the following scenario:

    I have a Captivate project with five modules, after each module, I want to have mandatory questions (users need to take and pass the course) and the optional questions (the user can jump, not included in the final grade). I use Oracle LMS. It seams Adobe changed not limited to 8 Captivate quiz preferences.

    I would like to hear from experts before making a long option. I have the opportunity to cut the project in five projects children with 5 quiz (with mandatory questions). take the quiz option questons as a sperate projects and organize them (learning objects) in the LMS to play after each module, where usage can jump.

    According to Lieve, since you need to mark the various questionnaires separately, you must have these quizzes of CP as separate files... which, as she says, is again a requirement of SCORM.

    You could put all the CP files separate together in one package with "Mode Multi-SCO" of Captivate, but in all cases I've seen, the LMS breaks those separate lessons anyway... so you will need to use the LMS to open one, go through it, close it, had him marked, open the other by the LMS, etc..

    The LMS would be the "Main file" Lieve mentions.

    If you do not NEED to see the scores of each quiz, you could put all the sections in a main CP file... then all the quizzes section would be marked cumulatively to display an overall score in the LMS...

    .. .and if your LMS supports 'interaction data' you could report on the real answers to each question to find out how well a user in each quiz section, but that again depends on your LMS capabilities (and that data meets the needs).

    Overall, however, if you need to separate the quiz scores in the main LMS interface, each quiz must be its own file. This would be the case with ANY tool you use, be a limitation of SCORM.

  • How to write a query to return rows with the varchar column that contains even a single occurrence of the characters, such as Ÿ and

    How to write a query to return rows with the varchar column that contains even a single occurrence of the characters, such as Ÿ and

    I have a table whose columns with values such as

    MINNEAŸPOLIS and ¿VV ¿A

    Only the characters that are allowed in this column are alphabets, numbers, spaces, points and supports.

    Please help to write a SQL SELECT with Regexp_like query or any other option.

    Thanks to you all! Under query worked for me. Thank you Frank to explain the concept of hooks inside regexp_like.

    SELECT * FROM testspecial, WHERE REGEXP_LIKE (sampletext, "[^] ^ A - Z ^ a - z ^ 0-9 ^ [^.]") ^ {^} ^]') ;

  • How to write a script for date get to the Clipboard

    Hi experts,

    How to write a script for date get to the Clipboard.

    the date format will be like this:

    05 - may

    respect of

    John

    Thanks guys, thanks Sanon

    I finally use the .bat doc

    like this:

    @@echo off
    for /f "delims =" % in (' wmic OS Get localdatetime ^ | find ".") "") Set "dt = %% a"
    the value "YYYY = % dt: ~ 0, 4%.
    the value "MM = % dt: ~ 4, 2%.

    If MM % is 01 set MM = January
    If % MM == 02 set MM = February
    If MM % is MM value = March 03
    If MM % is 04 MM value = April
    If MM % is 05 MM value = may
    If MM % is 06 MM value = June
    If MM % == 07 set MM = July
    If MM % is MM value = August 08
    If MM % is MM value = September 09
    If MM % is 10 MM value = October
    If MM % is 11A set MM = November
    If MM % is game MM 12 = December

    the value "DD = % dt: ~ 6, 2%.
    the value "HH = % dt: ~ 8, 2%.
    the value "Min = % dt: ~ 10, 2%.
    Set "s = % dt: ~ 12, 2%.

    Echo DD - MM HH % %% % Min | Clip

    It works

    respect of

    John

  • An error occurred when querying for the pending operations

    Original title: sysprep problem
    I have an acer aspire 5738Z, I use windows 7 (64 bit) I try to open sysprep.exe and it does not open, a text box appears saying "an error occurred when querying for the pending operations. What can I do to fix this?

    Hello

    Thanks for posting the request in the Microsoft community forums.
    I understand that you receive the error "an error has occurred when querying for outstanding operations" when trying to open sysprep.exe on the computer.

    You can try the solutions provide and check if it helps solve the issue.

    Method 1:
    You can scan System File Checker to fix corrupted files.
    How to use the System File Checker tool to fix the system files missing or corrupted on Windows Vista or Windows 7
    http://support.Microsoft.com/kb/929833

    Method 2:
    If the steps above fail then you can try the steps and check.

    a. run regedit by typing regedit in start search by pressing ENTER.
    b navigate to the following key:
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control
    Key: RegistrySizeLimit
    Type: REG_DWORD
    Value: 0xffffff (4294967295)
    c. reset.

    If you need help with Windows, keep us informed. We will be happy to help you.

  • Hierarchical + analysis of query for the parameters of the OU

    Hello gurus,

    I'm trying for a couple of hours there is a query works as I want.

    Our application needs to store settings for our organizational units. These organizational units are generally organized in a hierarchy manner: a high-level unit many units of the child. The settings are stored in another table with 1:1 relationship.

    For ease of visualization, here are the data of the organization unit and parameter table in a more visual format:
    SQL> select * from organization_unit;
    UNIT_CODE  UNIT_NAME            PARENT_UNIT_CODE
    ---------- -------------------- ----------------
    00000      Top level
    10         L2 unit #10          00000
    10-01      L3 unit #10-01       10
    10-02      L3 unit #10-02       10
    20         L2 unit #20          00000
    20-01      L3 unit #20-01       20
    20-02      L3 unit #20-02       20
    
    SQL>  select * from org_unit_parameters;
    UNIT_CODE  PARAM1               PARAM2               PARAM3               PARAM4
    ---------- -------------------- -------------------- -------------------- --------------------
    00000      Default value        Default value        Default value        {null}
    10         {null}               Value from 10        Value from 10        {null}
    10-01      {null}               {null}               Value from 10-01     {null}
    10-02      {null}               {null}               {null}               Value from 10-02
    20         Value from 20        Value from 20        Value from 20        {null}
    20-01      {null}               Value from 20-01     {null}               {null}
    20-02      {null}               Value from 20-02     {null}               {null}
    The application queries the table of parameters to get a parameter value for a given unit.
    The parameter resolution algorithm is pretty simple: when you query a unit, the applicable parameter is set to the required level. If the parameter is undefined (null) to the required level, the value of the parameter to be returned is defined next in the hierarchy parent. In some rare cases, it can be null if a parameter is not set anywhere from required at the top level.

    I made a request that seems to work when querying a unit at a time. It uses hierarchical operators (start by + connect by) with a bit of analytical functions. Here's a test & the raw output example:
    SQL> WITH hierarchy
      2  AS
      3  (
      4    SELECT ou.unit_code,
      5         LEVEL            AS lvl
      6    FROM   organization_unit ou
      7    START WITH
      8      ou.unit_code = '20-01'
      9    CONNECT BY
     10      ou.unit_code = PRIOR ou.parent_unit_code
     11  )
     12  SELECT h.*,
     13       p.param1                                                        AS param1_raw,
     14       LAST_VALUE (p.param1 IGNORE NULLS) OVER (ORDER BY h.lvl DESC)   AS param1_with_last,
     15       FIRST_VALUE(p.param1 IGNORE NULLS) OVER (ORDER BY h.lvl ASC)    AS param1_with_first,
     16       p.param2                                                        AS param2_raw,
     17       LAST_VALUE (p.param2 IGNORE NULLS) OVER (ORDER BY h.lvl DESC)   AS param2_with_last,
     18       FIRST_VALUE(p.param2 IGNORE NULLS) OVER (ORDER BY h.lvl ASC)    AS param2_with_first,
     19       p.param3                                                        AS param3_raw,
     20       LAST_VALUE (p.param3 IGNORE NULLS) OVER (ORDER BY h.lvl DESC)   AS param3_with_last,
     21       FIRST_VALUE(p.param3 IGNORE NULLS) OVER (ORDER BY h.lvl ASC)    AS param3_with_first,
     22       p.param4                                                        AS param4_raw,
     23       LAST_VALUE (p.param4 IGNORE NULLS) OVER (ORDER BY h.lvl DESC)   AS param4_with_last,
     24       FIRST_VALUE(p.param4 IGNORE NULLS) OVER (ORDER BY h.lvl ASC)    AS param4_with_first
     25  FROM   hierarchy                                h
     26         LEFT JOIN org_unit_parameters         p
     27         ON h.unit_code = p.unit_code
     28  ORDER BY h.lvl DESC;
    
    UNIT_CODE   LVL PARAM1_RAW           PARAM1_WITH_LAST     PARAM1_WITH_FIRST    PARAM2_RAW           PARAM2_WITH_LAST     PARAM2_WITH_FIRST    PARAM3_RAW           PARAM3_WITH_LAST     PARAM3_WITH_FIRST    PARAM4_RAW           PARAM4_WITH_LAST     PARAM4_WITH_FIRST
    ---------- ---- -------------------- -------------------- -------------------- -------------------- -------------------- -------------------- -------------------- -------------------- -------------------- -------------------- -------------------- --------------------
    00000         3 Default value        Default value        Value from 20        Default value        Default value        Value from 20-01     Default value        Default value        Value from 20        {null}               {null}               {null}
    20            2 Value from 20        Value from 20        Value from 20        Value from 20        Value from 20        Value from 20-01     Value from 20        Value from 20        Value from 20        {null}               {null}               {null}
    20-01         1 {null}               Value from 20        {null}               Value from 20-01     Value from 20-01     Value from 20-01     {null}               Value from 20        {null}               {null}               {null}               {null}
    Seems pretty good, higher settings are well "propagated" down with the LAST_VALUE function. But, I don't understand why the use of FIRST_VALUE and oppposite command does not give the same result. A little more play with the last query to get the final result of a given unit code:
    SQL> SELECT *
      2  FROM
      3  (
      4     WITH hierarchy
      5     AS
      6     (
      7        SELECT ou.unit_code,
      8               LEVEL            AS lvl
      9        FROM   organization_unit ou
     10        START WITH
     11           ou.unit_code = '20-01'
     12        CONNECT BY
     13           ou.unit_code = PRIOR ou.parent_unit_code
     14     )
     15     SELECT h.*,
     16            LAST_VALUE (p.param1 IGNORE NULLS) OVER (ORDER BY h.lvl DESC)   AS param1,
     17            LAST_VALUE (p.param2 IGNORE NULLS) OVER (ORDER BY h.lvl DESC)   AS param2,
     18            LAST_VALUE (p.param3 IGNORE NULLS) OVER (ORDER BY h.lvl DESC)   AS param3,
     19            LAST_VALUE (p.param4 IGNORE NULLS) OVER (ORDER BY h.lvl DESC)   AS param4
     20     FROM   hierarchy                                h
     21               LEFT JOIN org_unit_parameters         p
     22               ON h.unit_code = p.unit_code
     23     ORDER BY h.lvl
     24  )
     25  WHERE ROWNUM = 1;
    
    UNIT_CODE   LVL PARAM1               PARAM2               PARAM3               PARAM4
    ---------- ---- -------------------- -------------------- -------------------- --------------------
    20-01         1 Value from 20        Value from 20-01     Value from 20        {null}
    Works well!

    But my ultimate goal is to create a view that properly solve all these parameters for each level of the organization with the good spread rather in new queries for each unit at once. I played a little, but without success. :( My current gross query is the following:
    SQL> WITH hierarchy
      2  AS
      3  (
      4     SELECT ou.unit_code,
      5            LPAD(' ',2*(LEVEL-1)) || ou.unit_code    AS tree,
      6            LEVEL                                    AS lvl
      7     FROM   organization_unit ou
      8     START WITH
      9        parent_unit_code IS NULL
     10     CONNECT BY
     11        PRIOR unit_code =  parent_unit_code
     12  )
     13  SELECT h.*,
     14         p.param1                                                        AS param1_raw,
     15         LAST_VALUE (p.param1 IGNORE NULLS) OVER (ORDER BY h.lvl DESC)   AS param1_with_last,
     16         FIRST_VALUE(p.param1 IGNORE NULLS) OVER (ORDER BY h.lvl ASC)    AS param1_with_first,
     17         p.param2                                                        AS param2_raw,
     18         LAST_VALUE (p.param2 IGNORE NULLS) OVER (ORDER BY h.lvl DESC)   AS param2_with_last,
     19         FIRST_VALUE(p.param2 IGNORE NULLS) OVER (ORDER BY h.lvl ASC)    AS param2_with_first,
     20         p.param3                                                        AS param3_raw,
     21         LAST_VALUE (p.param3 IGNORE NULLS) OVER (ORDER BY h.lvl DESC)   AS param3_with_last,
     22         FIRST_VALUE(p.param3 IGNORE NULLS) OVER (ORDER BY h.lvl ASC)    AS param3_with_first,
     23         p.param4                                                        AS param4_raw,
     24         LAST_VALUE (p.param4 IGNORE NULLS) OVER (ORDER BY h.lvl DESC)   AS param4_with_last,
     25         FIRST_VALUE(p.param4 IGNORE NULLS) OVER (ORDER BY h.lvl ASC)    AS param4_with_first
     26  FROM   hierarchy                          h
     27            LEFT JOIN org_unit_parameters   p
     28            ON h.unit_code = p.unit_code
     29  ORDER BY h.unit_code;
    
    UNIT_CODE  TREE        LVL PARAM1_RAW                PARAM1_WITH_LAST          PARAM1_WITH_FIRST      PARAM2_RAW                   PARAM2_WITH_LAST          PARAM2_WITH_FIRST         PARAM3_RAW                PARAM3_WITH_LAST          PARAM3_WITH_FIRST         PARAM4_RAW                PARAM4_WITH_LAST       PARAM4_WITH_FIRST
    ---------- ---------- ---- ------------------------- ------------------------- ------------------------- ------------------------- ------------------------- ------------------------- ------------------------- ------------------------- ------------------------- ------------------------- ------------------------- -------------------------
    00000      00000         1 Default value             Default value             Default value          Default value                Default value             Default value             Default value             Default value             Default value             {null}                    Value from 10-02       {null}
    10           10          2 {null}                    Value from 20             Default value          Value from 10                Value from 10             Default value             Value from 10             Value from 10             Default value             {null}                    Value from 10-02       {null}
    10-01          10-01     3 {null}                    {null}                    Default value          {null}                       Value from 20-02          Default value             Value from 10-01          Value from 10-01          Default value             {null}                    Value from 10-02       Value from 10-02
    10-02          10-02     3 {null}                    {null}                    Default value          {null}                       Value from 20-02          Default value             {null}                    Value from 10-01          Default value             Value from 10-02          Value from 10-02       Value from 10-02
    20           20          2 Value from 20             Value from 20             Default value          Value from 20                Value from 10             Default value             Value from 20             Value from 10             Default value             {null}                    Value from 10-02       {null}
    20-01          20-01     3 {null}                    {null}                    Default value          Value from 20-01             Value from 20-02          Default value             {null}                    Value from 10-01          Default value             {null}                    Value from 10-02       Value from 10-02
    20-02          20-02     3 {null}                    {null}                    Default value          Value from 20-02             Value from 20-02          Default value             {null}                    Value from 10-01          Default value             {null}                    Value from 10-02       Value from 10-02
    As you can see, it's not that I was expecting. I know there is something to do with a PARTITION BY clause, but do not know how.
    Anyone know how to solve my problem?

    Thank you
    Bruno

    For the purposes of reproducibility, here is the code to create the structure and data:
    Here is the format of my paintings and a few samble data:
    CREATE TABLE organization_unit (
       unit_code         VARCHAR2(5 CHAR)   NOT NULL PRIMARY KEY,
       unit_name         VARCHAR2(100 CHAR) NOT NULL,
       parent_unit_code  VARCHAR2(5 CHAR)   
    );
    
    CREATE TABLE org_unit_parameters (
       unit_code         VARCHAR2(5 CHAR)   NOT NULL PRIMARY KEY,
       param1            VARCHAR2(100 CHAR),
       param2            VARCHAR2(100 CHAR),
       param3            VARCHAR2(100 CHAR),
       param4            VARCHAR2(100 CHAR)
    );
    
    -- Inserting data
    INSERT INTO organization_unit (unit_code, unit_name, parent_unit_code) 
    VALUES ('00000', 'Top level', NULL);
    
    INSERT INTO organization_unit (unit_code, unit_name, parent_unit_code) 
    VALUES ('10', 'L2 unit #10', '00000');
    
    INSERT INTO organization_unit (unit_code, unit_name, parent_unit_code) 
    VALUES ('10-01', 'L3 unit #10-01', '10');
    
    INSERT INTO organization_unit (unit_code, unit_name, parent_unit_code) 
    VALUES ('10-02', 'L3 unit #10-02', '10');
    
    INSERT INTO organization_unit (unit_code, unit_name, parent_unit_code) 
    VALUES ('20', 'L2 unit #20', '00000');
    
    INSERT INTO organization_unit (unit_code, unit_name, parent_unit_code) 
    VALUES ('20-01', 'L3 unit #20-01', '20');
    
    INSERT INTO organization_unit (unit_code, unit_name, parent_unit_code) 
    VALUES ('20-02', 'L3 unit #20-02', '20');
    
    INSERT INTO ORG_UNIT_PARAMETERS (unit_code, param1, param2, param3)
    VALUES ('00000', 'Default value', 'Default value', 'Default value');
    
    INSERT INTO ORG_UNIT_PARAMETERS (unit_code, param2, param3)
    VALUES ('10', 'Value from 10', 'Value from 10');
    
    INSERT INTO ORG_UNIT_PARAMETERS (unit_code, param3)
    VALUES ('10-01', 'Value from 10-01');
    
    INSERT INTO ORG_UNIT_PARAMETERS (unit_code, param4)
    VALUES ('10-02', 'Value from 10-02');
    
    INSERT INTO ORG_UNIT_PARAMETERS (unit_code, param1, param2, param3)
    VALUES ('20', 'Value from 20', 'Value from 20', 'Value from 20');
    
    INSERT INTO ORG_UNIT_PARAMETERS (unit_code, param2)
    VALUES ('20-01', 'Value from 20-01');
    
    INSERT INTO ORG_UNIT_PARAMETERS (unit_code, param2)
    VALUES ('20-02', 'Value from 20-02');
       
    COMMIT;

    Hi, Bruno.

    You almost had it!
    Take your query that gets good results for a single node. Remove the START WITH clause so that it does the same thing for each node. You will need to add CONNECT_BY_ROOT to remember what node you started with in each case and PARTITION BY calling value in all the LAST_VALUE function:

    WITH hierarchy
    AS
    (
         SELECT  ou.unit_code               AS ancestor_unit_code,
                     LEVEL                    AS lvl,
              CONNECT_BY_ROOT      ou.unit_code     AS descendant_unit_code
           FROM        organization_unit     ou
           CONNECT BY    ou.unit_code  = PRIOR  ou.parent_unit_code
    )
    , got_params     AS
    (
         SELECT       h.descendant_unit_code          AS unit_code
         ,       h.lvl
         ,       LAST_VALUE (p.param1  IGNORE NULLS) OVER ( PARTITION BY  h.descendant_unit_code
                                                                ORDER BY        lvl     DESC
                                               )    AS param1
         ,       LAST_VALUE (p.param2  IGNORE NULLS) OVER ( PARTITION BY  h.descendant_unit_code
                                                                ORDER BY        lvl     DESC
                                               )    AS param2
         ,       LAST_VALUE (p.param3  IGNORE NULLS) OVER ( PARTITION BY  h.descendant_unit_code
                                                                ORDER BY        lvl     DESC
                                               )    AS param3
         ,       LAST_VALUE (p.param4  IGNORE NULLS) OVER ( PARTITION BY  h.descendant_unit_code
                                                                ORDER BY        lvl     DESC
                                               )    AS param4
         FROM               hierarchy           h
         LEFT OUTER JOIN  org_unit_parameters     p  ON     h.ancestor_unit_code     = p.unit_code
    )
    SELECT       unit_code, param1, param2, param3, param4
    FROM       got_params
    WHERE       lvl     = 1
    ;
    

    Output:

    NIT_ PARAM1           PARAM2           PARAM3           PARAM4
    ----- ---------------- ---------------- ---------------- ----------------
    00000 Default value    Default value    Default value
    10    Default value    Value from 10    Value from 10
    10-01 Default value    Value from 10    Value from 10-01
    10-02 Default value    Value from 10    Value from 10    Value from 10-02
    20    Value from 20    Value from 20    Value from 20
    20-01 Value from 20    Value from 20-01 Value from 20
    20-02 Value from 20    Value from 20-02 Value from 20
    

    I hope that's what you want. I don't see the exact results you wanted posted anywhere.

    Thanks for posting the CREATE TABLE and INSERT statements; It is very useful.

    The difference between LAST_VALUE (... DESC) and FIRST_VALUE (... CSA) has to do with the default windowing.
    Say that we try to calculate FIRST_VALUE and LAST_VALUE on a line where lvl = 1, and it has 2 and 3 lvls in the same partition.
    LAST_VALUE (... ORDER BY DESC lvl) means the window includes lvl = values 1 and all the highest (i.e., 2 and 3).
    FRIST_VALUE (...) ORDER BY DESC lvl) means the window includes lvl = 1 and all the values (which, of course, their absence)
    It is because the widow of default is BETWEEN UNBOUNDED PREVIOUS AND CURRENT ROW, where "preceding" means lower values if you use ascending order, but higher values if you use descending order. We could use FIRST_VALUE to get the same results, but we will have to explicitly set the window in BETWEEN CURRENT_ROW AND UNBOUNDED FOLLOWING.

    Published by: Frank Kulash, November 12, 2010 12:46
    Additional explanation of LAST_VALUE

    Published by: Frank Kulash, November 12, 2010 13:04
    Beheading has been corrected.

  • Hi, I bought a windows xp disk Professional Microsoft a few years ago but never used it how can I cd key for the disc

    Hi, I bought a windows xp disk Professional Microsoft a few years ago but never used it how can I cd key for the disc

    If you bought a copy the retail of Windows key should be included in the box.

    How to get a replacement product key

    Retail Windows:
    If you have lost a product key for the software you purchased separately from your computer, or if your product key does not work, call Microsoft. To locate the phone number, visit the following Microsoft Web site: http://support.microsoft.com/default.aspx?scid=fh; CNTACTMS

    A fee may apply for lost keys.

  • Need driver for the following...

    Hello

    I've been hunting and can't seem to find the drivers for the following hardware id:

    PCI\VEN_10EC & DEV_5227 & SUBSYS_2166103C & REV_01

    Its there in the unknown device as a PCI Device Manager.

    This seems to be the realtek card reader, and be gone hollow other threads, I've tried 3-4 versions of realtek card reader drivers. None of them have worked.

    My laptop is a HP Pavilion n210se. Technical support/manual/drivers on its product page link is broken.

    http://WWW8.HP.com/emea_middle_east/en/products/laptops/product-detail.html?OID=6762356#! tab = function...

    Cannot find the model in the support/drivers of hp's global site download section.

    How can I get the card reader to work? (assuming that the unknown device is a card reader)

    Hello

    Please find the select network given below link and download the driver.

    The driver link

  • How can I contact Sandisk for the support of my device warranty refurbishing Fuze e280?

    How can I contact Sandisk for the support of my device warranty refurbishing Fuze e280? It came without a manual or an other such info...

    I called SanDisk to 866-726-3475.  They gave me a case # and took me through the steps to retrieve and format the e280.  They did not go to any purchase information.  After following the instructions, the e280 worked like new.

    Thank you
    E C Yarter

Maybe you are looking for

  • Empty miniature Pages from Sierra 5.6.2

    Everytime I open a doc Pages 5.6.2, the thumbnails on the left are empty. This used occasionally occur before moving to Sierra too. When this happened in the Capitan, two ways could be used:-1 / clicking in the doc himself would sometimes bring compl

  • NB200-10z heated at high temperature

    See screenshot:https://i.tinyuploads.com/REgsQ7.jpg Temperature is really high. My fan is also STOPPED. I use an external fan on the cushion. I'm living in Pakistan, there are no Toshiba service center. So advise me what I have to do?

  • [fpga] Configuration of analog input or 7965R

    Hi all I have a card FPGA NI FlexRIO (SMU-7965R) with an adaptation module (NI 5733). I'm using Labview real-time 2012. My measurements are dominated with harmonic sound of 60 Hz, which is most likely due to the ground loop. I try to put my analog in

  • Abandonment of the Internet Explorer Web sites

    Dell has replaced my hard drive today. I had to download all my software again.  Internet explore is working but will not be allowed to access some Web sites. An error message informs you that the page must be abandoned. Any ideas what the problem is

  • Trying to create a network of client server to work - fairly new to networking

    Hello I have a PC running Windows 7 Ultimate that I try to do the 'server' for my work network.  I have two other PC, one running Windows XP Pro and the other running Windows 8 Pro - these two, I'm doing the "clients".  The Windows 7 pc is connected