Several lines in a row with different column name

Hello
I have the table "v_Profile_ID" and "v_Trasaction".

V_profile_ID columns
1 profile_nbr
2 idendifaction_number

V_Trasaction columns (a historical data)
1 profile_nbr
2 Transaction_ID
3.TransactionDate_Time
4.Transaction_amount


common profile_nbr in the tables 'v_Profile_ID' and 'v_Trasaction '.

Are values in the v_profile_ID table

profile_nbr Identification_nbr

1001 Au1002
1001 BD9089
1001 FC3900


To view the identification_3 of v_profile_ID, identification_2, identification_1, Profile_nbr
and TransactionDate_Time Transaction_amount of v_Trasaction

Profile_nbr identification_1 identification_2 identification_3 TransactionDate_Time Transaction_amount

1001 Au1002 BD9089 FC3900 1000 2 April 2011


Please can someone help me

Thank you
Petrilla

Hello

Try this... !!

Select profile_nbr,
max(decode(seq,1,identification_nbr,null)) identification_1,
max(decode(seq,2,identification_nbr,null)) identification_2,
max(decode(seq,3,identification_nbrl,null)) identification_3

from (select profile_nbr,identification_nbr,row_number()
    over(partition by profile_nbr
       order by identification_nbr) seq
        from table_name) where seq<=3;
         group by profile_nbr;

Concerning
KPR

* If it's OK... then do as correct
* If it's useful... then make it as useful

Published by: KPR on April 29, 2011 04:53

Tags: Database

Similar Questions

  • SQL to convert a row with 4 columns to 4 rows with 1 column

    Sorry, I know this question has been asked hundreds of times before!

    This is my starting SQL:

    set linesize 500
    
    with tbl_data AS
     (select 'N' argument1, 'Y' argument2, NULL argument3, 'Y' argument4 from dual)
    select * from tbl_data;
    
    
    ARGUMENT1 ARGUMENT2 ARGUMENT3 ARGUMENT4
    --------- --------- --------- ---------
    N         Y                   Y        
    

    Is it possible to enter the data in this format:

                    COL_HEADING
    ARGUMENT1       N
    ARGUMENT2       Y
    ARGUMENT3       
    ARGUMENT4       Y
    

    I have read comments UNPIVOT but can't really work on the syntax to get a single line with 4 columns to appear as 4 rows with 1 column.

    Sorry - I realize that I'm probably be lazy and stupid.

    Any advice much appreciated, thank you.

    Hello

    Here's a way to do it with UNPIVOT:

    SELECT *.

    OF tbl_data

    MUST INCLUDE NULL VALUES

    (col_heading

    FOR column-name IN (argument1

    argument2

    argument3

    argument4

    )

    )

    ;

    Output:

    COLUMN COL_HEADING

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

    ARGUMENT1 N

    ARGUMENT2 Y

    ARGUMENT3

    ARGUMENT4 Y

  • Is it possible to migrate a planing with different database name application?

    Hi gurus,

    is 1] possible to migrate an application planing with different database name via the LCM in EMP 11 utility?

    [2] we can migrate application of planning with different names from DB in sys9 too?

    You must update this table, restart planning. You must also rename the database through the Regional service.

    See you soon

    John
    http://John-Goodwin.blogspot.com/

  • Swivel... Several lines in simple row, multiple column

    Dear Oracle Guru

    I have a table
    emp_req_order
    the fields are
    EmpNo, Deptno, req_order

    I need to find the max of Req_order for all dept

    so my request was

    SELECT max (req_order) emp_req_order Maxorder
    Deptno group

    put it was

    MaxOrder
    -----------
    45
    34
    23
    17

    I want the output of a line like

    45 34 23 17

    Instead of four rows data must be in a line, but four columns

    I searched the forum I even had a proposal as follows:
    Max (SELECT Decode(deptno,101,req_order)) const1,
    Const2 Max (decode(DEPTNO,102,req_order)),
    Const3 Max (decode(DEPTNO,103,req_order)),
    Const4 Max (decode(DEPTNO,104,req_order)),
    Of emp_req_order
    Group By deptno


    The output was still in several lines

    Kindly guide me in this regard

    with the best regards

    RSS

    SSR,

    Just drag the group clause for the purpose.

    Kind regards
    Rob.

  • merge multiple lines in a row (but multiple columns)

    How to merge multiple lines in a row (but several columns) effectively.

    For example

    IDVal IDDesc Id_Information_Type Attribute_2 Attribute_3 Attribute_4 Attribute_5 Attribute_1 IdNum
    23 asdc 1 location USA NM ABQ four seasons 87106
    23 asdc 1 Stats 2300 91.7 8.2 85432
    23 asdc 1 Audit 1996 June 17 1200
    AAFC 65 2 location USA TX AUS Hilton 92305
    65 AAC 2 Stats 5510 42.7 46 9999
    AAFC 65 2 Audit 1996 July 172 1100


    where different attributes mean different for each Information_type.
    For example, for Information_Type = location
    Attribute_1: countries
    Attribute_2: State and so on.


    For example, for Information_Type = Stats
    Attribute_1 designates the Population
    Attribute_2: percentage of ethnicity American and so on.

    I want to create a view that shows as below:

    IDVal IDDesc IDNum country state city hotel ZipCode American Population % other % area Audit year Audit AuditMonth Type AuditTime
    23 asdc 1 USA NM ABQ reviews 87106 2300 91.7 46 85432 1996 June 17 1200
    AAFC 65 2 USA TX AUS Hilton 92305 5510 42.7 46 9999 1996 July 172 1100


    Thank you

    Hello

    This is called pivoting . The FAQ forum has a section on this subject: {message identifier: = 9360005}

    I hope that answers your question.
    If not, post your best attempt, as well as some examples of data (CREATE TABLE and INSERT, only relevant columns instructions) and also publish outcomes from these data. (See you the desired results, but they are very difficult to read because they are not formatted. Use \.

     tags, as described in the forum FAQ, below.)
    Explain, using specific examples, how you get the results you want from the data given.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).  This is always important, but especially so with pivots.
    See the forum FAQ {message:id=9360002}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
    
  • SQL to convert a row with 4 columns, 4 rows by 4 columns

    With the help of Frank Kulash yesterday (https://community.oracle.com/thread/3810284)

    I can now use UNPIVOT start with this:

    with tbl_data AS  
     (select 'N' argument1, 'Y' argument2, NULL argument3, 'Y' argument4 from dual)  
    select * from tbl_data;  
    
    
    ARGUMENT1 ARGUMENT2 ARGUMENT3 ARGUMENT4  
    --------- --------- --------- ---------  
    N         Y                   Y   
    

    And eventually conversion of a single line of output to 4 rows and 2 columns via:

    with tbl_data AS
     (select 'N' argument1, 'Y' argument2, NULL argument3, 'Y' argument4 from dual)
        SELECT  *
        FROM    tbl_data
        UNPIVOT INCLUDE NULLS
                (    col_heading
                FOR  col_name  IN ( argument1
                                  , argument2
                                  , argument3
                                  , argument4
                                  )
                );
    
        COL_NAME  COL_HEADING
        --------- -----------
        ARGUMENT1 N
        ARGUMENT2 Y
        ARGUMENT3
        ARGUMENT4 Y
    

    I was wondering if there are sort of Frank solution can be modified to include the 2 columns (for example, COL_SEQ and COL_PROMPT) with them, hard coded values for example, '1' for the SEQ and 'TEST' for the GUEST, as I have the solution to a Frank's UNION with another query that returns the 4 columns.

    i.e. the performance:

    COL_NAME  COL_HEADING COL_SEQ     COL_PROMPT
    --------- ----------- ----------- -----------
    ARGUMENT1 N           1           TEST
    ARGUMENT2 Y           1           TEST
    ARGUMENT3             1           TEST
    ARGUMENT4 Y           1           TEST
    

    Thank you

    Hello

    969483 wrote:

    With the help of Frank Kulash yesterday (https://community.oracle.com/thread/3810284)

    I can now use UNPIVOT start with this:

    1. with tbl_data AS
    2. (select "n" argument1, argument2 'Y', NULL argument3, 'Y' double argument4)
    3. Select * from tbl_data;
    4. ARGUMENT1 ARGUMENT2, ARGUMENT3 ARGUMENT4
    5. --------- --------- --------- ---------
    6. N         Y                   Y

    And eventually conversion of a single line of output to 4 rows and 2 columns via:

    1. with tbl_data AS
    2. (select "n" argument1, argument2 'Y', NULL argument3, 'Y' double argument4)
    3. SELECT *.
    4. OF tbl_data
    5. MUST INCLUDE NULL VALUES
    6. (col_heading
    7. FOR column-name IN (argument1
    8. argument2
    9. argument3
    10. argument4
    11. )
    12. );
    13. COLUMN COL_HEADING
    14. --------- -----------
    15. ARGUMENT1 N
    16. ARGUMENT2 Y
    17. ARGUMENT3
    18. ARGUMENT4 Y

    I was wondering if there are sort of Frank solution can be modified to include the 2 columns (for example, COL_SEQ and COL_PROMPT) with them, hard coded values for example, '1' for the SEQ and 'TEST' for the GUEST, as I have the solution to a Frank's UNION with another query that returns the 4 columns.

    i.e. the performance:

    1. COLUMN COL_HEADING COL_SEQ COL_PROMPT
    2. --------- ----------- ----------- -----------
    3. ARGUMENT1 N 1 TEST
    4. ARGUMENT2 Y 1 TEST
    5. ARGUMENT3 1 TEST
    6. ARGUMENT4 Y 1 TEST

    Thank you

    Of course, you can include constants hardcoded in any set of results; just put constants in the SELECT clause and assign aliases for columns.

    Don't forget, I havef you need anything in the more SELECT clause *, then * must be qualified with a table name or alias, so that in this case, you can do something like:

    SELECT d. *.

    1 AS col_seq

    'TEST' AS col_prompt

    OF tbl_data

    MUST INCLUDE NULL VALUES

    (col_heading

    FOR column-name IN (argument1

    argument2

    argument3

    argument4

    )

    d

    ;

  • Transfer values of ROWTYPE in ROWTYPE with different COLUMN specifications. keeping the Default_Data values

    Hello

    I have a problem on dynamically the transfer values of different columns in two variables given rowtype type.

    My intention is to transfer values from table1 into table2.

    Basically, I stated to vars of v_table1 and v_table2% rowtype, each of them contains columns with the same, and also the individual column names.

    v_table2% rowtype must be initialized with default values.

    I would like to insert v_table2 values in table2 later by practice 'INSERT INTO TABLE2 VALUES v_table2'.

    Before inserting, I need to change several values of column by different rules, but these rules are not relevant for my actual demand.

    The point is, how can I transfer the values of v_table1 in v_table2 for the hanving of columns with the same column name, without hard-coding the names of columns, because these two tables contain many columns.

    In addition values initialized with v_table2 default_data values should not be overwritten by data does not exist in the same named column of v_table1.

    Example: If v_table1. D is NULL, it should not replace the default value initialized former "Monday".

    Conditions:

    Table 1 contains the following values:

    Column name Value
    A'1'
    B'2'
    CNULL VALUE
    D'somedata '.
    ENULL VALUE
    F« 3 »

    After the transfer of the values of v_table1 in v_table2, I guess that the following data:

    Column name Value Source
    CNULL VALUETable1.C
    D'somedata '.Table1.D
    E"Tuesday".DATA_DEFAULT from Table2
    F« 3 »Table1.F
    GNULL VALUE
    HNULL VALUE

    Right now I am already able to fill the v_table2 with the default values:

    declare
      lv_query varchar2(1000);
      
      type cur_typ is ref cursor;
      rcur_typ cur_typ;
      
      v_table2 table2%rowtype;
    
    begin
        for rec in (select *
                    from user_tab_columns
                    where table_name = 'TABLE2'
                    order by column_id
                    )
        loop
          if rec.data_default is null then
              lv_query := lv_query||', null';
            elsif rec.data_type = 'NUMBER' then
              lv_query := lv_query||', '||rec.data_default;
            elsif rec.data_type = 'DATE' then
              lv_query := lv_query||', '||rec.data_default;
            else
              lv_query := lv_query||', '||rec.data_default||'';
          end if;
        end loop;
        
        lv_query := 'SELECT'||substr(lv_query, 2)||' FROM DUAL';
        dbms_output.put_line(lv_query);
        
        open rcur_typ for lv_query;
        fetch rcur_typ into v_table2;
        close rcur_typ;
    end;
    

    I have no idea how to achieve the transfer of v_table1 to v_table2 without substitute default values of table2.


    As far as I know I can find these columns with column names by querying:

    select column_name from user_tab_cols where table_name='TABLE1' intersect select column_name from user_tab_cols where table_name='TABLE2'
    

    Maybe you can give me some advice.

    Thank you very much.

    Sample data:

    CREATE TABLE "TABLE1" 
       (    "A" VARCHAR2(20 BYTE), 
        "B" VARCHAR2(20 BYTE), 
        "C" VARCHAR2(20 BYTE), 
        "D" VARCHAR2(20 BYTE), 
        "E" VARCHAR2(20 BYTE), 
        "F" VARCHAR2(20 BYTE)
       );
    
      CREATE TABLE "TABLE2" 
       (    "C" VARCHAR2(20 BYTE), 
        "D" VARCHAR2(20 BYTE) DEFAULT 'Monday', 
        "E" VARCHAR2(20 BYTE) DEFAULT 'Tuesday', 
        "F" VARCHAR2(20 BYTE) DEFAULT 'Wednesday', 
        "G" VARCHAR2(20 BYTE) DEFAULT 'Thursday', 
        "H" VARCHAR2(20 BYTE)
       );
    
    INSERT INTO "TABLE1" (A, B, D, F) VALUES ('1', '2', 'somedata', '3');
    
    INSERT INTO "TABLE1" (A, B, D, F) VALUES ('1', '2', 'somedata', '3');
    

    Banner:

    Oracle Database 11 g 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

    You can build a dynamic query that checks the values of all columns in the table 1,

    and if a column contains null, then retrieves the default value of the column in table2,

    or null if this column doesn't have a default vallue.

    Something like this pseudocode

    SELECT
       if column A is not null then take A from table1, else take default for column A from table2
       .....
       if column X is not null then take A from table1, else take default for column X from table2
    FROM table1
    

    The default budget can be extracted from USER_TAB_COLUMNS

    select column_name, data_default from user_tab_columns
    where table_name = 'TABLE2'
    order by column_id
    ;
    
  • Creating a line chart series multi with different data providers

    I have 3 providers of data of the same structure that is ArrayCollection of data collection and that you want to use to create a line chart multiseriate. I don't have just 1 dataProvider that can be used but 3 different data providers of the same structure I want to use each different series.

    [Bindable] private var orangeSales: ArrayCollection = collection

    new ArrayCollection collection)

    [{sale: 101000, month: new Date (January 1, 2008 "")},]

    {sale: 960000, month: new Date (February 1, 2008 ')},

    {sale: 475000, month: new Date (March 1, 2008 ')},

    {sale: 425000, month: new Date (April 1, 2008 "")}

    ] );

    [Bindable] private var appleSales: ArrayCollection = collection

    new ArrayCollection collection)

    [{Sales: 991000, month: new Date (January 1, 2008 "")},]

    {sale: 140000, month: new Date (February 1, 2008 ')},

    {sale: 565000, month: new Date (March 1, 2008 ')},

    {sale: 255000, month: new Date (April 1, 2008 "")}

    ] );

    [Bindable] private var bananaSales: ArrayCollection = collection

    new ArrayCollection collection)

    [{sale: 891000, month: new Date (January 1, 2008 "")},]

    {sale: 147560, month: new Date (February 1, 2008 ')},

    {sale: 295000, month: new Date (March 1, 2008 ')},

    {sale: 574000, month: new Date (April 1, 2008 "")}

    ] );

    I want to create a line chart with orangeSales, appleSales and bananaSales as three different lines on the graph for different specified dates.

    < mx:ColumnChart showDataTips = "true" >

    < mx:horizontalAxis >

    < mx:CategoryAxis

    dataProvider = "{orangeSales}".

    categoryField = 'months '.

    / >

    < / mx:horizontalAxis >

    < mx:series >

    < mx:LineSeries displayName = "OrangeSales" yField = "sale" xField = "month" dataProvider = "{orangeSales}" / >

    < mx:LineSeries displayName = "AppleSales" yField = "sale" xField = "month" dataProvider = "{appleSales}" / >

    < mx:LineSeries displayName = "BananaSales" yField = "sale" xField = "month" dataProvider = "{bananaSales}" / >

    < / mx:series >

    < / mx:ColumnChart >

    Help, please!

    Sorry for the confusion. In fact I do something wrong, such as using ColumnChart to display a line chart or something like that.

    Now, I realized that a multi series line graph can be built by the presence of a different data provider for each of the LineSeries object.

    If the code below would create a multi series line graph:

    [Bindable] private var orangeSales: ArrayCollection = collection

    new ArrayCollection collection)

    [{sale: 101000, month: new Date (January 1, 2008 "")},]

    {sale: 960000, month: new Date (February 1, 2008 ')},

    {sale: 475000, month: new Date (March 1, 2008 ')},

    {sale: 425000, month: new Date (April 1, 2008 "")}

    ] );

    [Bindable] private var appleSales: ArrayCollection = collection

    new ArrayCollection collection)

    [{Sales: 991000, month: new Date (January 1, 2008 "")},]

    {sale: 140000, month: new Date (February 1, 2008 ')},

    {sale: 565000, month: new Date (March 1, 2008 ')},

    {sale: 255000, month: new Date (April 1, 2008 "")}

    ] );

    [Bindable] private var bananaSales: ArrayCollection = collection

    new ArrayCollection collection)

    [{sale: 891000, month: new Date (January 1, 2008 "")},]

    {sale: 147560, month: new Date (February 1, 2008 ')},

    {sale: 295000, month: new Date (March 1, 2008 ')},

    {sale: 574000, month: new Date (April 1, 2008 "")}

    ] );

    I want to create a line chart with orangeSales, appleSales and bananaSales as three different lines on the graph for different specified dates.

    <>

    dataProvider = "{orangeSales}".

    categoryField = 'months '.

    />

  • Divide the data in row in different columns

    Hi all
    I have a table with a column as below.
    col1
    ------------
    / shared
    / shared/dashboard invites you
    / shared/dashboard of the guests/statistics_from_to_p
    / Shared/Filters
    / Shared/Filters/_filters
    / shared/Summary Reports
    / shared/reports/age_gender_r summary
    / shared/TRC explore _portal/edge/DB tables / dashboard layout

    Here, I want to split these data delimited by "/" and the need to show as below. I tried with substr and instr functions, but I could not achieve.
    col1 Col2 col3 col4 col5 col
    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    / shared shared null null null null
    / shared/dashboard guest shared Dashboard prompt null null null
    / Shared/Dashboard Dashboard shared guests/statistics_from_to_p invites statistics_from_to_p null null
    / Shared/shared Filters filters null null null
    / Shared/Filters/_filters shared filters _filters null null
    / shared/Summary Reports shared null null null Summary Reports
    / Shared/Summary reports/shared age_gender_r null null age_gender_r summary reports
    Explore _portal/edge/DB tables layout / dashboard/Shared/TRC shared _portal TRC dashboard layout of dashboard Explorer tree
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Appreciate your help.

    Thank you.
  • How to make a NULL handle with different columns

    Hi gurus,

    I need the Oracle in the reports:

    For example:-J' have a Temp table with three columns A, B and C

    My requirement is IF the columns A, B and C are null in the report he should return C 0, B as none and none.
    If all values are there in columns A, B or C, then report output should return these values.

    All your contributions are much appreciated.

    Thank you

    When column c is null, column should return zero and column b return zero and column c 0.
    If column C is not null, then it must return the values that are present in their respective columns.

    select nvl2 (c, a, 'None') a, nvl2 (c, b, 'None') b, nvl (c, 0) c from temp
    
  • Find photos with different file names?

    Somehow, I have photos with different names. Example: 2015-04-08 13.28.25.jpg and IMG_1668.JPG.

    Trying to get all the photos into the Lightroom Catalog, I am unable to find any pictures unless I know the two names - which I did not.

    And my DuplicateFinder are not nameless a base file name.

    Any ideas?

    Sheila

    Lightroom doesn't have a function automated for something like that, but there are third-party plug-ins. See, for example, here: Finding of pictures duplicate in Lightroom

  • several devices on the network with the same name

    I want to install Windows 7 OS computers on a domain with Small Business SERVER 2003.  Curiously, I see all the computers on the network, where I should be able to, but one of them WK02011, is not accessible from all Windows 7 systems because there are multiple devices with the same name on the network according to a diagnosticn check.  WK02011 is visible and accessible from other systems on the network that are runjning XP OS.  There is only one device named WK02011 on the network.  I don't have this problem with any other XP system - that is - I can see and access all of the other XP machines on the network with the exception of WK02011.  I can't access WK2011 from the server and the server indicates that it is multiple devices with the same ID.  Rename the XP would be complicated because of having to re - set up the service to the customer and then turn around and install 7 OS in the workstation in the coming days.

    How to find the ghost device double?

    Hello

    Your question is more complex than what is generally answered in the Microsoft Answers forums. It is better suited for Windows 7 on TechNet. Please post your question in the Technet forums. You can follow the link to your question:

  • Build &amp; write to text with different column formatting

    3 days, I just pass on what appears to be a simple problem:

    I have a VI that reads a significant length TDMS file containing data sampled at 1 MHz 2-channel (very large files of course). The VI only runs 1 second at a time and looking for threshold crossing points and calculates the energy at this time there. In any case, I'm writing a text file where a column contains the number of the sample and the second column contains energy, annexed whenever the VI iterates (the number of rows generated by iteration may vary). It's simple by using the function 'Write to Spreasheet', the problem is I want a different format on each column. The sample number must be set to zero decimal and energy must be set on, say, 3 significant digits.

    A typical few lines should look like (delimited by tab characters, commas are there to represent the tabs):

    Time (samples), energy

    267935, 0.0000346

    545227, 0.000298

    1298655, 0.0000000122

    1314522, 0.00854

    'Write to Spreasheet' allows only a single format, so I have either a large number of DPs on my number of sample or energy value is 0.

    If I use 'Table in chain worksheet', I can set the formatting, but I can't seem to be concatenated, to build or to transpose the outputs in the right direction, no matter what I try.

    In the attached image I use Ch1 as my experience; CH2 using the traditional but unsatisfactory method "to write to the spreadsheet. The current VI returns on Ch1:

    Time (samples), energy

    267935

    545227

    0.0000346

    0.000298

    1298655

    1314522

    0.0000000122

    0.00854

    I hope that the image of the relevant part of the VI just go. I can reach the VI if necessary, but it seems unnecessary that I won't be able to share the data files for the tests.

    You can use the 'number of fractional string' primitive to convert data DBL to the chain with the required precesion. Then when you use this string 2D array and write in the file using 'write to the worksheet VI' it should work fine.

    If you still face any question please include the code with the data in a constant and registered in the 2012 version.

  • display the data in a row and different columns in the listbox

    Hi I want to disply data in different and same columns line in listbox using InsertListItem(), but it displays data in different lines... I use the escape sequence for the creation of columns... Also, I want to display an integer which I converted to a string using sprintf() on listbox with a Word, for example 10 Kg where 10 is stored in a variable and I must add Kg, how to do it in a single call to InsertItemList()... Thank you

    I see: you must create all of the line before adding it to the list box:

    sprintf (string, "&d\033p30l%s\033p100l%s\033p170l%d\033p220l%.2f", itemNo, itemName, itemPack, 123, 15.98);
    InsertListItem (panel, PANEL_LISTBOX , 0, string, 0);
    
  • generate several lines of each row in a table

    Hi all, consider the following data
    with data1 as
    (
      select 1 id, 0 cust_sh, null mx_sh, 123 cust_coll from dual union all
      select 2 id,0 cust_sh, 0 mx_sh, 0 cust_coll from dual union all
      select 3 id,456 cust_sh, 890 mx_sh, 123 cust_coll from dual 
    ),
    data2 as
    (
      select 'cust_sh' col_nm, 'ABC' nm from dual union all
      select 'mx_sh' col_nm, 'BDC' nm from dual union all
      select 'cust_coll' col_nm, 'HGR' nm from dual 
    )
    what I'm trying to do here is to join the two tables sort and produce this output
    id  nm         amt
    =====================
    1   HGR        123
    3   ABC        456
    3   BDC        890
    3   HGR        123
    That's how I get this result. Data1 has lines with the ID and the columns with quantities such as cust_sh, etc.
    data2 bearing the name of the column in data1 under col_nm and an additional column as nm.

    for each line of Data1, I should take the amount column, look in database2 and the data1 amount is greater than 0.
    then display the output.

    for example, to get data1 row1. cust_sh is set to 0, so we don't look this column in Database2. mx_sh is set to null, which is not greater than 0, then us none.
    cust_coll has the value 123 so we wait for this column in Database2. This is the third row in Database2. Therefore, view us the id and the amt of Data1 and data2 nm.

    for line two of Data1, all after id columns are 0. don't have no need to display the output. only when the amount is greater than zero, we watch in Database2.

    third row, cust sh has value 456 so we expect in database2 and we found in the first row. mx_sh has a value of 890 (greater than 0) so again once we look at Database2 and display the output.

    can someone help me with a query that produces the output above?

    Thanks in advance

    OK, two more options:

    WITH pivot_data1 AS (
      SELECT id, 'cust_sh' as col_nm, cust_sh as amt
      FROM data1
      WHERE cust_sh > 0
      UNION ALL
      SELECT id, 'mx_sh', mx_sh
      FROM data1
      WHERE mx_sh > 0
      UNION ALL
      SELECT id, 'cust_coll', cust_coll
      FROM data1
      WHERE cust_coll > 0
    )
    SELECT d1.id
         , d2.nm
         , d1.amt
    FROM pivot_data1 d1
         JOIN data2 d2 ON d2.col_nm = d1.col_nm
    ;
    
    WITH pivot_data1 AS (
      SELECT id
           , case i when 1 then 'cust_sh'
                    when 2 then 'mx_sh'
                    when 3 then 'cust_coll'
             end as col_nm
           , case i when 1 then cust_sh
                    when 2 then mx_sh
                    when 3 then cust_coll
             end as amt
      FROM data1
           CROSS JOIN ( SELECT level i FROM dual CONNECT BY level <= 3 )
    )
    SELECT d1.id
         , d2.nm
         , d1.amt
    FROM pivot_data1 d1
         JOIN data2 d2 ON d2.col_nm = d1.col_nm
    WHERE d1.amt > 0
    ;
    

Maybe you are looking for

  • No puedo descargar applications

    Buenos dias, Ayer me compre UN Iphone 6s Y Cuando Me Quiero descargar una application don't me already, nisiquera sell me a cartel or nada, Pongo en "Get" no da none answer, al me vuelve appear 'Get' Como UN Segundo if no one puesto nada Agradeceria

  • How can I change the elements of an Enum to execution?

    I have an enum that is full of items. I would like to change the labels on these elements using the runtime. When I try using the property node '[] strings' I get the following error: "Error 1073 in property node (arg 1). Possible reasons: LabVIEW: T

  • VPN tunnel between the concentrator 3005 and router Cisco 827

    I am trying to establish a VPN tunnel between the Central Office with VPN 3005 and controller branch Cisco 827 router. There is a router of perimeter with access set up in front of the 3005 list. I quote the ACLs on the Central perimeter router instr

  • Resolve namespace conflicts

    I have a column in one of my paintings with an index, whose name is, say TABLE_IDX1v1. TABLE_IDX1v1 is not the name, I gave, it was originally TABLE_IDX1, but I think the Data Modeler think that there is already a name index, so it adds the v1, but I

  • Based on ADF - BC in architecture at several levels

    I don't know if this is the right forum (Jdev and ADF) to ask that question. If this isn't the case, please suggest me the right section. I need to display a table with 10 columns and the records come from two different levels (a BPM and other from t