Merge two column value in single column

Team,
I have a requirement where in I need to merge 2 column values in a single column.
ex. I have Percent_complete column in my table. and my table has only one record.
I need to query such that I need to store the values of percent_complete and (100- percent_complete) values in a single column.
ex
Percent complete has 30 value.
I need to select 30 and 70(100-30) both in a single column.
Thanks,

SQL> select  *
  2    from  tbl
  3  /
PERCENT_COMPLETE
              30
SQL> select  abs(grouping(1) * 100 - max(percent_complete)) percent_complete
  2    from  tbl
  3    group by rollup(1)
  4  /
PERCENT_COMPLETE
              30
              70
SQL> select  nvl(percent_complete,100 - max(percent_complete)) percent_complete
  2    from  tbl
  3    group by rollup(percent_complete)
  4  /
PERCENT_COMPLETE
              30
              70
SQL>
SY.

Similar Messages

  • How to concatenate two colums into one single column

    I need some ideas to concatenate two different columns into one single column using a set of distinct values.
    For Example,
    Customer Product Number
    xyz A 1
    xyz B 2
    xyz B 1
    AAA C 7
    AAA A 1
    The result should look like this,
    Customer Value
    xyz A1 B2 B1
    AAA C7 A1
    How would I group this into once value ?
    Thanks in advance ...

    Tom's discussion of writing your own aggregate routines
    http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:2196162600402
    starts off with a link to the 8i alternatives
    "see
    http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:229614022562
    for 8i methods (not aggregates)"
    Unforutnately, it's a lot more work in 8i.
    Justin

  • Combining two columns into a single column

    Hi,
    I have a VC Iview which displays the data of a query in a table .
    Output in a Table    
    ......................<<Quantity>>               <<Unit>>                     <<Amount>>               <<Currency>>
    &&Sales&&                                 
    Is it possible in VC to combine "Quantity" column and "unit" column to a single column say "Quantity"
    similarly "Amount" column and "currency" column to a single column"Amount"
    I.e i wanted to show the values in a single column some thing like this:
    &&Sales:&&                     <<120 Kg>>                                            <<500 Dollars>> ( 2 columns )
    Instead of( 4 columns) :
    &&Sales :&&           << 120>>              <<Kg>>                <<500>>                           <<Dollars>>
    Thanks
    P.Navakanth

    Hi,
    You could hide your actual columns for Quanity and unit and create one more column of type expression box in your table that will concatenate the value of quantity and unit.
    Regards,
    Murtuza Kharodawala

  • Merging two records in a single record for the same matnr,werks and bwart.

    Hi I have a requirement to merge two records into one single record using the quantity field from MSEG table.
    I am selecting two records from the table MSEG. Now for these two records i have to add the quantity values into one variable.
    Then there should be only one record for the same matnr,werks,bwart.
    Any suggestion would be appreciated.
    Regards,
    Amit

    hi,
    You can COLLECT statement only if all non key fields are numeric.
    This statement Adds all such fields and give us a single record.
    Regards
    Sumit Agarwal

  • Displaying 2 columns in a single column using HTML section of reports.

    Hi Team,
    I have a requirement in which we need to display 2 columns in the same column of OBIEE report. At present we have 2 columns as 2 different columns.
    For example if i have a column A which is used as @A in html section i need the new column to have @A + @B where B is another column in database.
    Can i concatenate 2 columns in a single column ?
    Thanks,
    Ritesh

    first select column 1 and column 2 in criteria.
    go to reaults are add narrater view.
    in narrater view type.
    @1@2[br/]
    set number of rows
    this should work in narrator.
    Edited by: user10615659 on May 20, 2013 4:30 PM

  • Merge Two Columns in a Single Column

    Dear,
    Inputs
    Table1 |
    Col1 (Number) |
    1 |
    2 |
    3 |
    4 |
    5 |
    6 |
    and table 2
    Table2 |
    Col1 (Number) |
    7 |
    8 |
    9 |
    10 |
    11 |
    12 |
    No relation between the two tables
    I want to write a select statement that will result
    Column
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    No sorting is required, I just need to have all the values listed in a single column... How can I do?
    Thanks in Advance.

    If there is dup values between the two tables and you want get only unique, use UNION. If not UNION ALL as already stated.
    Nicolas.

  • Concatenate multiple row values into single column value

    Hello,
    Can anyone please refresh my memory on how to concatenate multiple row values into a single column value.
    In the following query, I will get multiple denial reasons per application and I would rather return all denial reasons on one line.
    SELECT a.application_id, a.membership_number,
    r.reason_text AS denial_reason,
    a.appl_receipt_date AS application_receipt_date,
    a.plan_request_1 AS application_plan_code,
    a.adjudication_date AS application_denial_date
    FROM application a, PLAN p, application_reason ar, reason r
    WHERE a.plan_request_1 = p.plan_cd
    AND a.application_id = ar.application_id
    AND ar.reason_id = r.reason_id
    AND a.adjudication_cd = 'D'
    AND a.appl_receipt_date BETWEEN '01-jan-2006' AND '31-dec-2006'
    AND p.plan_type_id = 12 and a.application_id = :appId
    ORDER BY application_id
    Any help is greatly appreciated.
    Thanks,
    -Christine

    found the following
    SELECT deptno,
           LTRIM(MAX(SYS_CONNECT_BY_PATH(ename,','))
           KEEP (DENSE_RANK LAST ORDER BY curr),',') AS employees
    FROM   (SELECT deptno,
                   ename,
                   ROW_NUMBER() OVER (PARTITION BY deptno ORDER BY ename) AS curr,
                   ROW_NUMBER() OVER (PARTITION BY deptno ORDER BY ename) -1 AS prev
            FROM   emp)
    GROUP BY deptno
    CONNECT BY prev = PRIOR curr AND deptno = PRIOR deptno
    START WITH curr = 1;
        DEPTNO EMPLOYEES
            10 CLARK,KING,MILLER
            20 ADAMS,FORD,JONES,SCOTT,SMITH
            30 ALLEN,BLAKE,JAMES,MARTIN,TURNER,WARD
    3 rows selected.at http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php

  • Concat rows values into single column

    Hi All,
    How can I concat values of a multiple rows into a single column by separating them by comma.
    Eg:
    SELECT empno FROM emp;
    empno
    1
    2
    3
    4
    I want output should be:
    Empnos
    1,2,3,4
    Thanks & Regards,
    Danish

    MichaelS wrote:
    Or
    SQL>  select rtrim(xmlagg(xmlelement(e, empno || ',')).extract('//text()').extract('//text()') ,',') empnos from emp
    EMPNOS                                                                         
    7369,7499,7521,7566,7654,7698,7782,7788,7839,7844,7876,7900,7902,7934 
    Hi Michael,
    is it an error or is it correct to put extract 2 times? This is giving to me the same result:
    select rtrim(xmlagg(xmlelement(e, empno || ',')).extract('//text()'),',') empnos from emp;
    EMPNOS                                                                         
    7369,7499,7521,7566,7654,7698,7782,7788,7839,7844,7876,7900,7902,7934           Regards.
    Al

  • Combine 2 specific column values into one column

    Is there an easy solution to combine column values that is in a group?
    In my report I have 1 column group named Activity_Area which has 5 different values Activity 1, Activity2...Activity5.
    Let's say I want to merge Activity 4 and Activity 5 and call it ActivityX and gives me the output as below
    Activity 1 | Activity 2 | Activity 3 | ActivityX

    Hi Jhonny86,
    According to your description, you create a field in database and it contains five values. Then you want to only display four values in report column group, and the last two values should be replaced by “ActivityX”, right?
    In your scenario, you can create an table like below:
    create table Act(id int,activity varchar(99))
    insert into Act select 1,'Activity 1'
    insert into Act select 2,'Activity 2'
    insert into Act select 3,'Activity 3'
    insert into Act select 4,'Activity 4'
    insert into Act select 5,'Activity 5'
    Then query the table with code like below in query designer, then add the field [Act] into the column group.
    If you have any question, please feel free to ask.
    Best regards,
    Qiuyun Yu
    Qiuyun Yu
    TechNet Community Support

  • Converting multiple column rows into single column

    Hi all Below is my requirement, can you anybody help me solve it. CREATE TABLE TYPE (   c1_type  VARCHAR2 (10),   c2_type  VARCHAR2 (10),   c3_type  VARCHAR2 (10),   c4_type  VARCHAR2 (10),   c5_type  VARCHAR2 (10),   c6_type  VARCHAR2 (10),   c7_type  VARCHAR2 (10),   c8_type  VARCHAR2 (10),   c9_type  VARCHAR2 (10)); INSERT INTO TYPE     VALUES ('Region_D',             'Region_E',             'Region_F',             'Region_D',             'Region_E',             'Region_D',             'Region_M',             'Region_D',             'Region_E'); commit; Acutal output on the below query select * from type; C1_TYPE C2_TYPE C3_TYPE C4_TYPE C5_TYPE C6_TYPE C7_TYPE C8_TYPE C9_TYPE Region_D Region_E Region_F Region_D Region_E Region_D Region_M Region_D Region_E Acutal i am expecting the below output,how to make it using query or using oracle built in function. Region_D Region_D Region_D Region_D Region_E Region_E Region_E Region_F Region_M

    Hi,
    So, you want to put the column values in alphabetic order, with the earliest value in c1_type and the last in c9_type, is that it?
    The fact that you even want to do this says that this is a bad table design.  If sorting the values makes sense, then putting them all in the same column on 9 different rows (rather than 9 different columns on 1 row) makes sense.
    If you're stuck with the current design, then use SELECT ... UNPIVOT to put them on separate rows, then use the analytic ROW_NUMBER function to assign numbers 1-9 to each value, and finally use SELECT ... PIVOT to put them back into 1 row in that order.  If you're not familiar with the built-in UNPIVOT and PIVOT features, look them up in the SQL Language manual, and see the forum FAQ:
    https://forums.oracle.com/message/9362005
    If you get stuck, post your best attempt (formatted), the exact results you want (formatted), and your Oracle version (e.g. 11.2.0.2.0).
    Also, TYPE is an Oracle keyword, so it's not a good table name.  Use something like location_type instead.

  • Merging Two Views in a Single Role

    Hello All,
    I wanted to Merge two iviews with in a single role.Consider the below example.
    See, i have a role called "Role A"(TLN1 Entry) and i have two url views( iView1 and iView2) which needs to be added and it should fall under the as TLN2 entry.
    Now i have two set of groups( Group A and Group B) , if i add this role to these two groups, users who all are part of "Group A" should see the "iView1" and users who all are part of "Group  B" should see the "iView2".
    I have read some help documentation, but i could understood the concept of merging.But i would like to know, how this can be achieved.
    Please help me.
    Thanks In Advance.
    Best Regards,
    Manoj K

    Hello both,
    Thanks for the quick reply.
    I am clear now. But one thing which i would like to know, is there any possibility, if these two iviews are assigned to a single role, and this roles is assigned to two groups, basically group A and group B,  only one group of people can should see Iview1 and other group of people should see iview2.( As per i know, access can be organized via roles, but still i wanted to check with you is there any provision where i can achieve this.
    Thanks for helping me.
    Best Regards,
    Manoj K

  • How to disable JTable Column Dragging (only single column)

    How could i disable a single column from being dragged in JTable?
    I need to fix the first column from being dragged in JTable and all other columns except the first can be dragged. how would i accomplish this task ?
    well, i know how to fix all column in jtable from being dragged using
    table.getTableHeader().setReorderingAllowed(false);But dont know how to fix only a single column. is there any method for doing this. or i have to implement any other logic?
    Please help me !
    Thanks

    The question is why do you have this requirement. I figure if the user wants to reorder the colum, let them, the table won't break.
    Maybe something like this would be acceptable:
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.table.*;
    public class FixedColumnScrollPane extends JScrollPane
        public FixedColumnScrollPane(JTable main, int fixedColumns)
            super( main );
            //  Use the table to create a new table sharing
            //  the DataModel and ListSelectionModel
            JTable fixed = new JTable( main.getModel() );
            fixed.setFocusable( false );
            fixed.setSelectionModel( main.getSelectionModel() );
            fixed.getTableHeader().setReorderingAllowed( false );
    //        fixed.getTableHeader().setResizingAllowed( false );
            fixed.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
            main.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
            //  Remove the fixed columns from the main table
            for (int i = 0; i < fixedColumns; i++)
                TableColumnModel columnModel = main.getColumnModel();
                columnModel.removeColumn( columnModel.getColumn( 0 ) );
            //  Remove the non-fixed columns from the fixed table
            while (fixed.getColumnCount() > fixedColumns)
                TableColumnModel columnModel = fixed.getColumnModel();
                columnModel.removeColumn( columnModel.getColumn( fixedColumns ) );
            //  Add the fixed table to the scroll pane
            fixed.setPreferredScrollableViewportSize(fixed.getPreferredSize());
            setRowHeaderView( fixed );
            setCorner(JScrollPane.UPPER_LEFT_CORNER, fixed.getTableHeader());
        public static void main(String[] args)
            //  Build your table normally
            JTable table = new JTable(10, 8);
            table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
            JScrollPane scrollPane= new FixedColumnScrollPane(table, 1 );
            JFrame frame = new JFrame("Table Fixed Column Demo");
            frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
            frame.getContentPane().add( scrollPane );
            frame.setSize(400, 300);
            frame.setVisible(true);
    }Or maybe you should be using a Row Header. A row header is like the column header of JTable. It remains fixed on the left side of the scroll pane. Search the forum for examples using "setrowheaderview".

  • How to merge three columns values to single row values in sql server 2008

    Hi Frds.....
    I have three quantity in my table.
    Quantity1,quantity2,quantity3
    this three quantity have different values
    ex:
    quantity1 = 1000,quantity2=2000,quantity3=3000
    the three column combine 2 display in single row values. this values display in one by one.
    ex: quantity
         1000
         2000
         3000

    You will need to use the UNPIVOT operator:
    DECLARE @example TABLE
    Id int NOT NULL IDENTITY(1,1),
    Quantity1 int,
    Quantity2 int,
    Quantity3 int
    INSERT INTO @example VALUES (1000, 2000, 3000), (4000, 5000, 6000);
    SELECT * FROM @example;
    SELECT Id, Quantity, QuantityType
    FROM @example
    UNPIVOT
    Quantity FOR QuantityType IN (Quantity1, Quantity2, Quantity3)
    ) AS u;
    Output:
    (2 row(s) affected)
    Id Quantity1 Quantity2 Quantity3
    1 1000 2000 3000
    2 4000 5000 6000
    (2 row(s) affected)
    Id Quantity QuantityType
    1 1000 Quantity1
    1 2000 Quantity2
    1 3000 Quantity3
    2 4000 Quantity1
    2 5000 Quantity2
    2 6000 Quantity3
    (6 row(s) affected)

  • Merge Two Tables with the same columns but different data

    I have a table that has the following columns:
    Current Table Definition
    commonname
    family
    genus
    species
    subspecies
    code
    I have a number of entries that don’t fit the current table definition – that is that they only have a common name or description and a code. These records don’t actually represent a species but are needed for data entry because they represent an object that may be encountered in the study (Bare Ground – which isn’t a species but would need to be recorded if encountered). So I would really like 2 tables:
    Table 1 Miscellaneous
    name
    code
    Table 2 Plant Species
    commonname
    family
    genus
    species
    subspecies
    code
    I would like two tables so I can enforce certain constraints on my species table like requiring that the family, genus, species, subspecies combination is unique. I can’t do this if I have all the “other” records that don’t have a family, genus, species, or subspecies unless I put in a lot of dummy data into the fields to make each record unique. I don’t really want to do this because these miscellaneous records really don’t represent a specific species.
    So – the problem is that while I want this data separate I will need to point a column from another table to the code column in both tables.
    How is this best done? Table? View? Merge?

    Hi,
    Actually you don't have to use scope refs. Sorry but I misunderstood you earlier. Here is a complete example that does exactly what you want. Notice how I added the constraint to the materialized view. Also notice when we try to insert a code in tbl3 that doesn't exist in the view, we get an error. HTH.
    SQL> create table tbl1 (name varchar2(10), code varchar2(3) primary key);
    Table created.
    SQL> create table tbl2 (commonname varchar2(10), code varchar2(3) primary key);
    Table created.
    SQL> insert into tbl1 values ('n1','c1');
    1 row created.
    SQL> insert into tbl1 values ('n2','c2');
    1 row created.
    SQL> insert into tbl1 values ('n3','c3');
    1 row created.
    SQL> insert into tbl2 values ('name1','c1');
    1 row created.
    SQL> insert into tbl2 values ('name2','c2');
    1 row created.
    SQL> insert into tbl2 values ('name3','c3');
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> create materialized view view1 as select name, commonname, tbl1.code from tbl1, tbl2 where tbl1.code = tbl2.code;
    Materialized view created.
    SQL> select * from view1;
    NAME COMMONNAME COD
    n1 name1 c1
    n2 name2 c2
    n3 name3 c3
    SQL> create table tbl3 (code varchar2(3), record varchar2(1));
    Table created.
    SQL> alter table view1 add constraint view1pk primary key (code); -- <-Note how I added a constraint to the view
    Table altered.
    SQL> alter table tbl3 add constraint tbl3fk foreign key (code) references view1(code);
    Table altered.
    SQL> insert into tbl3 values ('c1','r');
    1 row created.
    SQL> insert into tbl3 values ('c99','r');
    insert into tbl3 values ('c99','r')
    ERROR at line 1:
    ORA-02291: integrity constraint (RAJS.TBL3FK) violated - parent key not found
    SQL> spool of;
    -Raj Suchak
    [email protected]

  • Update all null columns value in single row statement

    4) Write a single SQL statement to update all the columns of a table to have -9 instead of null value
    e.g:
    Before update:
    C1     C2     C3
    null     9     null
    10     null     88
    12     8     0
    After update:
    C1     C2     C3
    -9     9     -9     
    10     -9     88
    12     8     0
    Thanks

    Hi,
    Update < table name >
    set column name = nvl(column name, -9),
    column name = nvl(column name, -9)
    Regards
    Message was edited by:
    Seshu

Maybe you are looking for