How To Concatenate Column Values from Multiple Rows into a Single Column?

How do I create a SQL query that will concatenate column values from multiple rows into a single column?
Last First Code
Lesand Danny 1
Lesand Danny 2
Lesand Danny 3
Benedi Eric 7
Benedi Eric 14
Result should look like:
Last First Codes
Lesand Danny 1,2,3
Benedi Eric 7,14
Thanks,
David Johnson

Starting with Oracle 9i
select last, first, substr(max(sys_connect_by_path(code,',')),2) codes
from
(select last, first, code, row_number() over(partition by last, first order by code) rn
from a)
connect by last = prior last and first = prior first and prior rn = rn -1
start with rn = 1
group by last, first
LAST       FIRST      CODES                                                                                                                                                                                                  
Lesand         Danny          1,2,3
Benedi         Eric           7,14Regards
Dmytro

Similar Messages

  • Create a view to shows data from multiple rows in a single column

    Hi all - this is probably posted in the wrong forum but I couldn't find which was the correct one.
    I am almost a complete novice at sql but I have a need to create a view which can be developed at 10g (which runs efficiently as the volumes are likely to be high) which will do the following.
    Original table with columns Parent_code, Child_code
    Parent_Code Child_Code
    1000 2000
    1000 3000
    1000 4000
    2000 3000
    2000 5000
    (note Parents can have multiple children and a child can have multiple parents!)
    What I need to end up with in my view is the following
    Child_Code Parent_List
    2000 '1000 (3)'
    3000 '1000 (3), 2000 (2)'
    4000 '1000 (3)'
    5000 '2000 (2)'
    Note the number in parantheses is the number of children that the parent has - ie in the original table parent 1000 has 3 rows (one for each child)
    This view is then to be used as a look up (on child code) for a business objects report.
    Is there anyone who could PLEASE, PLEASE help me fairly quickly on this as I have very little time to find a solution?

    Hi,
    You can test these ones :
    select child_code
         , ltrim(sys_connect_by_path(parent_info,', '), ', ') as parent_list
    from (
      select child_code
           , to_char(parent_code) ||
             ' (' ||
             count(*) over(partition by parent_code) ||
             ')' as parent_info
           , row_number() over(partition by child_code order by parent_code) rn
      from your_table
    where connect_by_isleaf = 1
    connect by prior rn = rn-1
           and prior child_code = child_code
    start with rn = 1
    select child_code,
           rtrim(
             extract(
               xmlagg(xmlelement("e",parent_info||', ') order by parent_info)
             , '//text()'
           ) as parent_list
    from (
      select child_code,
             to_char(parent_code) ||
             ' (' ||
             count(*) over(partition by parent_code) ||
             ')' as parent_info
      from your_table
    group by child_code
    ;What you need is called "string aggregation".
    See here for various techniques, including the two above : http://www.oracle-base.com/articles/misc/StringAggregationTechniques.php

  • Concatenate a column value across multiple rows - PDW

    We are using PDW based on SQL2014. We require an efficient logic on how to concatenate a column value across multiple rows. We have the following table
    T1
    (CompanyID, StateCD)
    Having following rows:
    1              NY
    1              NJ
    1              CT
    2              MA
    2              NJ
    2              VA
    3              FL
    3              CA
    We need a code snippet which will return following result set:
    1                    
    CT,NJ,NY
    2                    
    MA,NJ,VA
    3                    
    CA,FL
    We have tried built-in function STUFF with FOR XML PATH clause and it is not supported in PDW. So, we need a fast alternative.

    Hi Try this:
    SELECT * INTO #ABC
    FROM 
    SELECT 1 AS ID,'NY' AS NAME
    UNION 
    SELECT 1 AS ID,'NJ' AS NAME
    UNION 
    SELECT 1 AS ID,'CT' AS NAME
    UNION 
    SELECT 2 AS ID,'MA' AS NAME
    UNION 
    SELECT 2 AS ID,'NJ' AS NAME
    UNION 
    SELECT 2 AS ID,'VA' AS NAME
    UNION 
    SELECT 3 AS ID,'FL' AS NAME
    UNION 
    SELECT 3 AS ID,'CA' AS NAME
    )A
    CREATE TABLE ##CDB (ID INT, NAME NVARCHAR(800)) 
    DECLARE @TMP VARCHAR(MAX), 
            @V_MIN INT,
    @V_MAX INT,
    @V_COUNT INT
    SELECT @V_MIN=MIN(ID),@V_MAX=MAX(ID) FROM #ABC 
    SET @V_COUNT=@V_MIN
    WHILE @V_COUNT<=@V_MAX
    BEGIN
    SET @TMP = '' SELECT @TMP = @TMP + CONVERT(VARCHAR,NAME) + ', ' FROM #ABC 
    WHERE ID=@V_COUNT
    INSERT INTO ##CDB (ID, NAME) SELECT @V_COUNT AS ID ,CAST(SUBSTRING(@TMP, 0, LEN(@TMP)) AS VARCHAR(8000)) AS NAME 
    SET @V_COUNT=@V_COUNT+1
    END
    SELECT * FROM ##CDB
    OR
    SELECT * INTO #ABC
    FROM 
    SELECT 1 AS ID,'NY' AS NAME
    UNION 
    SELECT 1 AS ID,'NJ' AS NAME
    UNION 
    SELECT 1 AS ID,'CT' AS NAME
    UNION 
    SELECT 2 AS ID,'MA' AS NAME
    UNION 
    SELECT 2 AS ID,'NJ' AS NAME
    UNION 
    SELECT 2 AS ID,'VA' AS NAME
    UNION 
    SELECT 3 AS ID,'FL' AS NAME
    UNION 
    SELECT 3 AS ID,'CA' AS NAME
    UNION 
    SELECT 5 AS ID,'LG' AS NAME
    UNION 
    SELECT 5 AS ID,'AP' AS NAME
    )A
    CREATE TABLE ##CDB (ID INT, NAME NVARCHAR(800)) 
    DECLARE @TMP VARCHAR(MAX), 
            @V_MIN INT,
    @V_MAX INT,
    @V_COUNT INT
    SELECT @V_MIN=MIN(ID),@V_MAX=MAX(ID) FROM #ABC 
    SET @V_COUNT=@V_MIN
    WHILE @V_COUNT<=@V_MAX
    BEGIN
    SET @TMP = '' SELECT @TMP = @TMP + CONVERT(VARCHAR,NAME) + ', ' FROM #ABC 
    WHERE ID=@V_COUNT
    SELECT @V_COUNT AS ID ,CAST(SUBSTRING(@TMP, 0, LEN(@TMP)) AS VARCHAR(8000)) AS NAME INTO #TEMP 
    INSERT INTO ##CDB (ID, NAME) SELECT ID, NAME FROM #TEMP WHERE NAME<>''
    DROP TABLE #TEMP
    SET @V_COUNT=@V_COUNT+1
    END
    SELECT * FROM ##CDB
    Thanks Shiven:) If Answer is Helpful, Please Vote

  • How to get one value from multiple duplication for a key figure field

    Hi expert,
          I have a infoprovider, with following format:
            employee     hourly_rate   action_type  count of action
         there are multiple rows for each employee, I want to create query as follows:
            employee     hourly_rate   action_type  count of action
         in which hourly_rate is constant , only retriving one value from multiple rows for one employee, count of action should be summarized. 
    how to get this hourly_rate.
    Many Thanks,

    Hi,
    put the employee in rows panel -> reaming object put it in free char panel.
    suppress the all result rows for the all object except employee .
    select the object -> go to query properties -> select display tab -> select result rows -> select suppress.
    select the employee -> go to query properties -> select display tab -> select result rows -> select always display. - now it will give employee wise hourly rate summarize data.
    Thanks,
    Phani.

  • Reg : Concatenation of a column value with multiple rows... URGENT

    Hello,
    Could any of u help me in concatenating a column value with
    multiple rows ???
    For ex : I've the following data from emp table :
    DEPTNO ENAME
    10 KING'S
    30 BLAKE
    10 CLARK
    10 TOM JONES
    30 ALLEN
    30 JAMES
    20 SMITH
    20 SCOTT
    20 MILLER
    10 MILLER
    20 rajeev
    I want the following output :
    deptno Concat_value
    10 KING'S,CLARK,TOM JONES,MILLER
    20 Rajeev,MILLER,SMITH,SCOTT
    30 BLAKE,ALLEN,JAMES
    Thanks in Advance,
    Srini

    Hello Naveen,
    Thanks for ur answer. But I need a single SQL query for getting
    what I want. I know the solution in PL/SQL.
    Please try it in a single SQL....
    Thanks again,
    Srini

  • How to get a value from one item into another

    How can i get value from one item into another item.
    Ex: I have a report, in there i have check boxes, and when i have checked some rows, and press submitt, a prosses computates it into a item on another page, and a branche redirects to page 3. Then i'm going to use the value in the item into a PL/SQL script in an report to show the submittet items.
    How can i do this?
    Computation script, pages and all that is fixed. But i dont know which PL/SQL statement to use to get th value from the item.

    Hi Fredr1k,
    Use the V() function from pl/sql.
    e.g. V('P3_MY_ITEM')
    will return the value of that page item.
    As long as the pl/sql is called from within the Apex environment.
    Regards
    Michael

  • Collecting data from multiple rows into one column

    I'd like to run a query and put a collection of items into one output column instead of multiple rows. See the example below:
    Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Prod
    PL/SQL Release 10.2.0.5.0 - Production
    "CORE     10.2.0.5.0     Production"
    TNS for 32-bit Windows: Version 10.2.0.5.0 - Production
    NLSRTL Version 10.2.0.5.0 - Production
         CREATE TABLE "SKIP"."INGREDIENTS"
       (     "INGRED_ID" NUMBER,
         "INGRED_NAME" VARCHAR2(20 BYTE),
         "STORES" VARCHAR2(20 BYTE)
       ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "USERS" ;
    REM INSERTING into SKIP.INGREDIENTS
    Insert into SKIP.INGREDIENTS (INGRED_ID,INGRED_NAME,STORES) values (1,'SEA SALT','Food lion');
    Insert into SKIP.INGREDIENTS (INGRED_ID,INGRED_NAME,STORES) values (2,'TABLE SALT','Food lion');
    Insert into SKIP.INGREDIENTS (INGRED_ID,INGRED_NAME,STORES) values (3,'FLOUR','Piggly Wiggly');
    Insert into SKIP.INGREDIENTS (INGRED_ID,INGRED_NAME,STORES) values (4,'YEAST',null);
    Insert into SKIP.INGREDIENTS (INGRED_ID,INGRED_NAME,STORES) values (5,'BEER','ABC Store');
      CREATE TABLE "SKIP"."PRETZELS"
       (     "PRETZEL_ID" NUMBER,
         "PRETZEL_NAME" VARCHAR2(20 BYTE),
         "PRETZEL_DESC" VARCHAR2(100 BYTE)
       ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "USERS" ;
    REM INSERTING into SKIP.PRETZELS
    Insert into SKIP.PRETZELS (PRETZEL_ID,PRETZEL_NAME,PRETZEL_DESC) values (1,'CLASSIC','Classic knot pretzel');
    Insert into SKIP.PRETZELS (PRETZEL_ID,PRETZEL_NAME,PRETZEL_DESC) values (2,'THICK STICK','Straight pretzel, abt 1/2" in dia');
      CREATE TABLE "SKIP"."INGRED_XREF"
       (     "PRETZEL_ID" NUMBER,
         "INGRED_ID" NUMBER
       ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "USERS" ;
    REM INSERTING into SKIP.INGRED_XREF
    Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (1,1);
    Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (1,2);
    Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (1,4);
    Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (2,2);
    Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (2,3);
    Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (2,5);
    --  Constraints for Table INGRED_XREF
      ALTER TABLE "SKIP"."INGRED_XREF" MODIFY ("PRETZEL_ID" NOT NULL ENABLE);
      ALTER TABLE "SKIP"."INGRED_XREF" MODIFY ("INGRED_ID" NOT NULL ENABLE);
    {code}
    Desired output (note how the ingredients are all listed in one column, separated by commas):
    {code}
    PRETZEL_ID PRETZEL_NAME     PRETZEL_DESC                        INGREDIENTS
    1          CLASSIC          Classic knot pretzel                SEA SALT, TABLE SALT, YEAST
    2          THICK STICK      Straight pretzel, abt 1/2" in dia   TABLE_SALT, FLOUR, BEER

    See the FAQ : {message:id=9360005}
    Especially links concerning string aggregation.

  • How can I insert values from table object into a regular table

    I have a table named "ITEM", an object "T_ITEM_OBJ", a table object "ITEM_TBL" and a stored procedure as below.
    CREATE TABLE ITEM
    ITEMID VARCHAR2(10) NOT NULL,
    PRODUCTID VARCHAR2(10) NOT NULL,
    LISTPRICE NUMBER(10,2),
    UNITCOST NUMBER(10,2),
    SUPPLIER INTEGER,
    STATUS VARCHAR2(2),
    ATTR1 VARCHAR2(80),
    ATTR2 VARCHAR2(80),
    ATTR3 VARCHAR2(80),
    ATTR4 VARCHAR2(80),
    ATTR5 VARCHAR2(80)
    TYPE T_ITEM_OBJ AS OBJECT
    ITEMID VARCHAR2(10),
    PRODUCTID VARCHAR2(10),
    LISTPRICE NUMBER(10,2),
    UNITCOST NUMBER(10,2),
    SUPPLIER INTEGER,
    STATUS VARCHAR2(2),
    ATTR1 VARCHAR2(80),
    ATTR2 VARCHAR2(80),
    ATTR3 VARCHAR2(80),
    ATTR4 VARCHAR2(80),
    ATTR5 VARCHAR2(80)
    TYPE ITEM_TBL AS TABLE OF T_ITEM_OBJ;
    PROCEDURE InsertItemByObj(p_item_tbl IN ITEM_TBL, p_Count OUT PLS_INTEGER);
    When I pass values from my java code through JDBC to this store procedure, how can I insert values from the "p_item_tbl" table object into ITEM table?
    In the stored procedure, I wrote the code as below but it doesn't work at all even I can see values if I use something like p_item_tbl(1).itemid. How can I fix the problem?
    INSERT INTO ITEM
    ITEMID,
    PRODUCTID,
    LISTPRICE,
    UNITCOST,
    STATUS,
    SUPPLIER,
    ATTR1
    ) SELECT ITEMID, PRODUCTID, LISTPRICE,
    UNITCOST, STATUS, SUPPLIER, ATTR1
    FROM TABLE( CAST(p_item_tbl AS ITEM_TBL) ) it
    WHERE it.ITEMID != NULL;
    COMMIT;
    Also, how can I count the number of objects in the table object p_item_tbl? and how can I use whole-loop or for-loop to retrieve values from the table object?
    Thanks.

    Sigh. I answered this in your other How can I convert table object into table record format?.
    Please do not open multiple threads. It just confuses people and makes the trreads hard to follow. Also, please remember we are not Oracle employees, we are all volunteers here. We answer questions if we can, when we can. There is no SLA so please be patient.
    Thank you for your future co-operation.
    Cheers, APC

  • How can i store values from my String into Array

    Hi guys
    i wants to store all the values from my string into an array,,,, after converting them into intergers,,,, how i can do this becs i have a peice of code which just give me a value of a character at time,,,,charat(2)...BUT i want to the values from String to store in an Array
    here is my peice of code which i m using for 1 char at time
    int[] ExampleArray2 = new int[24];
    String tempci = "Battle of Midway";
    for(int i=0;i>=tempci.length();i++)
    int ascii = tempci.charAt(i); //Get ascii value for the first character.

    public class d1
         public static final void main( String args[] )
              int[] ExampleArray2 = new int[24];
              String tempci = "Battle of Midway";
              for(int i=0;i<tempci.length();i++)
                   int ascii = tempci.charAt(i);
                   ExampleArray2=ascii;
              for(int i=0;i<ExampleArray2.length;i++)
                   System.out.println(ExampleArray2[i]);

  • Need help with turning multiple rows into a single row

    Hello.
    I've come across a situation that is somewhat beyond my knowledge base. I could use a little help with figuring this out.
    My situation:
    I am attempting to do some reporting from a JIRA database. What I am doing is getting the dates and times for specific step points of a ticket. This is resulting in many rows per ticket. What I need to do is return one row per ticket with a calculation of time between each step. But one issue is that if a ticket is re-opened, I want to ignore all data beyond the first close date. Also, not all tickets are in a closed state. I am attaching code and a sample list of the results. If I am not quite clear, please ask for information and I will attempt to provide more. The database is 10.2.0.4
    select jiraissue.id, pkey, reporter, summary
    ,changegroup.created change_dt
    ,dbms_lob.substr(changeitem.newstring,15,1) change_type
    ,row_number() OVER ( PARTITION BY jiraissue.id ORDER BY changegroup.created ASC ) AS order_row
    from jiraissue
    ,changeitem, changegroup
    ,(select * from customfieldvalue where customfield = 10591 and stringvalue = 'Support') phaseinfo
    where jiraissue.project = 10110
    and jiraissue.issuetype = 51
    and dbms_lob.substr(changeitem.newstring,15,1) in ('Blocked','Closed','Testing','Open')
    and phaseinfo.issue = jiraissue.id
    and changeitem.groupid = changegroup.id
    and changegroup.issueid = jiraissue.id
    order by jiraissue.id,change_dt
    Results:
    1     21191     QCS-91     Error running the Earliest-deadlines flight interface request/response message     2008-07-16 9:30:38 AM     Open     1
    2     21191     QCS-91     Error running the Earliest-deadlines flight interface request/response message     2008-07-16 11:37:02 AM     Testing     2
    3     21191     QCS-91     Error running the Earliest-deadlines flight interface request/response message     2010-06-08 9:14:52 AM     Closed     3
    4     21191     QCS-91     Error running the Earliest-deadlines flight interface request/response message     2010-09-02 11:29:37 AM     Open     4
    5     21191     QCS-91     Error running the Earliest-deadlines flight interface request/response message     2010-09-02 11:29:42 AM     Open     5
    6     21191     QCS-91     Error running the Earliest-deadlines flight interface request/response message     2010-09-02 11:29:50 AM     Testing     6
    7     21191     QCS-91     Error running the Earliest-deadlines flight interface request/response message     2010-09-02 11:29:53 AM     Closed     7
    8     23234     QCS-208     System Baseline - OK button does not show up in the Defer Faults page for the System Engineer role      2008-10-03 10:26:21 AM     Open     1
    9     23234     QCS-208     System Baseline - OK button does not show up in the Defer Faults page for the System Engineer role      2008-11-17 9:39:39 AM     Testing     2
    10     23234     QCS-208     System Baseline - OK button does not show up in the Defer Faults page for the System Engineer role      2011-02-02 6:18:02 AM     Closed     3
    11     23977     QCS-311     Tally Sheet - Reason Not Done fails to provide reason for unassigned tasks     2008-09-29 2:44:54 PM     Open     1
    12     23977     QCS-311     Tally Sheet - Reason Not Done fails to provide reason for unassigned tasks     2010-05-29 4:47:37 PM     Blocked     2
    13     23977     QCS-311     Tally Sheet - Reason Not Done fails to provide reason for unassigned tasks     2011-02-02 6:14:57 AM     Open     3
    14     23977     QCS-311     Tally Sheet - Reason Not Done fails to provide reason for unassigned tasks     2011-02-02 6:15:32 AM     Testing     4
    15     23977     QCS-311     Tally Sheet - Reason Not Done fails to provide reason for unassigned tasks     2011-02-02 6:15:47 AM     Closed     5

    Hi,
    Welcome to the forum!
    StblJmpr wrote:
    ... I am attempting to do some reporting from a JIRA database. What is a JIRA database?
    I am attaching code and a sample list of the results. If I am not quite clear, please ask for information and I will attempt to provide more. Whenever you have a question, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and the results you want from that data.
    Simplify the problem as much as possible. For example, if the part you don't know how to do only involves 2 tables, then jsut post a question involving those 2 tables. So you might just post this much data:
    CREATE TABLE     changegroup
    (      issueid          NUMBER
    ,      created          DATE
    ,      id          NUMBER
    INSERT INTO changegroup (issueid, created, id) VALUES (21191,  TO_DATE ('2008-07-16 09:30:38 AM', 'YYYY-MM-DD HH:MI:SS AM'),  10);
    INSERT INTO changegroup (issueid, created, id) VALUES (21191,  TO_DATE ('2008-07-16 11:37:02 AM', 'YYYY-MM-DD HH:MI:SS AM'),  20);
    INSERT INTO changegroup (issueid, created, id) VALUES (21191,  TO_DATE ('2010-06-08 09:14:52 AM', 'YYYY-MM-DD HH:MI:SS AM'),  90);
    INSERT INTO changegroup (issueid, created, id) VALUES (21191,  TO_DATE ('2010-09-02 11:29:37 AM', 'YYYY-MM-DD HH:MI:SS AM'),  10);
    INSERT INTO changegroup (issueid, created, id) VALUES (21191,  TO_DATE ('2010-09-02 11:29:42 AM', 'YYYY-MM-DD HH:MI:SS AM'),  10);
    INSERT INTO changegroup (issueid, created, id) VALUES (21191,  TO_DATE ('2010-09-02 11:29:50 AM', 'YYYY-MM-DD HH:MI:SS AM'),  20);
    INSERT INTO changegroup (issueid, created, id) VALUES (21191,  TO_DATE ('2010-09-02 11:29:53 AM', 'YYYY-MM-DD HH:MI:SS AM'),  90);
    INSERT INTO changegroup (issueid, created, id) VALUES (23234,  TO_DATE ('2008-10-03 10:26:21 AM', 'YYYY-MM-DD HH:MI:SS AM'),  10);
    INSERT INTO changegroup (issueid, created, id) VALUES (23234,  TO_DATE ('2008-11-17 09:39:39 AM', 'YYYY-MM-DD HH:MI:SS AM'),  20);
    INSERT INTO changegroup (issueid, created, id) VALUES (23234,  TO_DATE ('2011-02-02 06:18:02 AM', 'YYYY-MM-DD HH:MI:SS AM'),  90);
    INSERT INTO changegroup (issueid, created, id) VALUES (23977,  TO_DATE ('2008-09-29 02:44:54 PM', 'YYYY-MM-DD HH:MI:SS AM'),  10);
    INSERT INTO changegroup (issueid, created, id) VALUES (23977,  TO_DATE ('2010-05-29 04:47:37 PM', 'YYYY-MM-DD HH:MI:SS AM'),  30);
    INSERT INTO changegroup (issueid, created, id) VALUES (23977,  TO_DATE ('2011-02-02 06:14:57 AM', 'YYYY-MM-DD HH:MI:SS AM'),  10);
    INSERT INTO changegroup (issueid, created, id) VALUES (23977,  TO_DATE ('2011-02-02 06:15:32 AM', 'YYYY-MM-DD HH:MI:SS AM'),  20);
    INSERT INTO changegroup (issueid, created, id) VALUES (23977,  TO_DATE ('2011-02-02 06:15:47 AM', 'YYYY-MM-DD HH:MI:SS AM'),  90);
    CREATE TABLE     changeitem
    (      groupid          NUMBER
    ,      newstring     VARCHAR2 (10)
    INSERT INTO changeitem (groupid, newstring) VALUES (10, 'Open');
    INSERT INTO changeitem (groupid, newstring) VALUES (20, 'Testing');
    INSERT INTO changeitem (groupid, newstring) VALUES (30, 'Blocked');
    INSERT INTO changeitem (groupid, newstring) VALUES (90, 'Closed');Then post the results you want to get from that data, like this:
    ISSUEID HISTORY
      21191 Open (0) >> Testing (692) >> Closed
      23234 Open (45) >> Testing (807) >> Closed
      23977 Open (607) >> Blocked (249) >> Open (0) >> Testing (0) >> ClosedExplain how you get those results from that data. For example:
    "The output contains one row per issueid. The HISTORY coloumn shows the different states that the issue went through, in order by created, starting with the earliest one and continuing up until the first 'Closed' state, if there is one. Take the first row, issueid=21191, for example. It started as 'Open' on July 16, 2008, then, on the same day (that is, 0 days later) changed to 'Testing', and then, on June 8, 2010, (692 days later), it became 'Closed'. That same issue opened again later, on September 2, 2010, but I don't want to see any activity after the first 'Closed'."
    The database is 10.2.0.4That's very important. Always post your version, like you did.
    Here's one way to get those results from that data:
    WITH     got_order_row     AS
         SELECT     cg.issueid
         ,     LEAD (cg.created) OVER ( PARTITION BY  cg.issueid
                                          ORDER BY      cg.created
                  - cg.created            AS days_in_stage
         ,       ROW_NUMBER ()     OVER ( PARTITION BY  cg.issueid
                                          ORDER BY      cg.created
                               )    AS order_row
         ,     ci.newstring                     AS change_type
         FROM    changegroup     cg
         JOIN     changeitem     ci  ON   cg.id     = ci.groupid
         WHERE     ci.newstring     IN ( 'Blocked'
                           , 'Closed'
                           , 'Testing'
                           , 'Open'
    --     AND     ...          -- any other filtering goes here
    SELECT       issueid
    ,       SUBSTR ( SYS_CONNECT_BY_PATH ( change_type || CASE
                                                             WHEN  CONNECT_BY_ISLEAF = 0
                                           THEN  ' ('
                                              || ROUND (days_in_stage)
                                              || ')'
                                                         END
                                    , ' >> '
               , 5
               )     AS history
    FROM       got_order_row
    WHERE       CONNECT_BY_ISLEAF     = 1
    START WITH     order_row          = 1
    CONNECT BY     order_row          = PRIOR order_row + 1
         AND     issueid               = PRIOR issueid
         AND     PRIOR change_type     != 'Closed'
    ORDER BY  issueid
    ;Combining data from several rows into one big delimited VARCHAR2 column on one row is call String Aggregation .
    I hope this answers your question, but I guessed at so many things, I won't be surprised if it doesn't. If that's the case, point out where this is wrong, post what the results should be in those places, and explain how you get those results. Post new data, if necessary.

  • Numbers: Copy/Paste from multiple tables into 1 single Table?

    I would appreciate some guidance in creating a copy/paste script from multiple numbers tables into a different single table within the same numbers document.
    The columns in the source table are in different positions to the destination table.
    So for example, i would want to copy…
    Sheet 1, Table 1 Cell A3  copy to Sheet 2 Table Z Cell B2
    Sheet 1, Table 1 Cell B3  copy to Sheet 2 Table Z Cell C2
    Sheet 1, Table 1 Cell C3  copy to Sheet 2 Table Z Cell E2
    Sheet 1, Table 1 Cell D3  copy to Sheet 2 Table Z Cell F2
    Sheet 1, Table 1 Cell E3  copy to Sheet 2 Table Z Cell G2
    Sheet 1, Table 1 Cell G3  copy to Sheet 2 Table Z Cell I2
    Sheet 1, Table 1 Cell J3  copy to Sheet 2 Table Z Cell H2
    and repeat the copy/paste on subsequent rows of each table until there is an empty row in Sheet 1 Table 1 (or if this is difficult, say set the repeat to a max of 30 rows).
    The script would then need to move on to Sheet 1 Table 2, and do the same copying to Sheet 2 Table Z (from where the previous copy/paste finished in Table Z).
    Repeat process would finalise with Sheet 1 Table 6.
    The Paste part would need to be pasting values, as the cells in the source tables do contain some formulas.
    At the moment this is all done manually and does take some to to undertake.
    If anyone can help, i would be very grateful.
    Thanks,
    Colin

    Interceptor,
    are you trying to aggregate data from severl tables into a single table?  If so you whould be able to do this without a script.  The function indirect() will allow you to construct the proper formula, which you may fill over (in the same row) to the appropriate cells, then fill down.
    Here is a small example:
    There are three data tables ("Table 1", "Table 2", and "Table 3").  And a summary "Table Z"
    In table Z make the first row a header (as shown):
    Use column A to enter the Sheet name and colomn B to enter the table name.
    In row 1 (the header), enter the cells you want to get
    in cell C2 type (or copy and paste from here) the formula:
    =INDIRECT($A2&"::"&$B2&"::"&C$1)
    now select cell C2, copy now select cell C2 thru H2, paste
    now select the cells C2 thu H2, hover the corsor over the bottom edge of the selection, and drag the yellow cirlc down as needed to fill the formula down.
    Update the sheet and table names as needed for each row

  • Custom row-fetch and how to get column values from specific row of report

    Hi -- I have a case where a table's primary key has more than 3 columns. My report on the
    table has links that send the user to a single-row DML form, but of course the automatic
    fetch won't work because 1) I can't set more than 3 item values in the link and 2) the
    auto fetch only handles 2 PK columns.
    1)
    I have written a custom fetch (not sure it's the most elegant, see second question) that is working
    for 3 or few PK columns (it references the 1-3 item values set in the link), but when there are
    more than 3, I don't know how to get the remaining PK column values for the specific row that was
    selected in the report. How can I access that row's report column values? I'll be doing it from the
    form page, not the report page. (I think... unless you have another suggestion.)
    2)
    My custom fetch... I just worked something out on my own, having no idea how this is typically
    done. For each dependent item (database column) in the form, I have a source of PL/SQL
    function that queries the table for the column in question, using the primary key values. It works
    beautifully, though is just a touch slow on my prototype table, which has 21 columns. Is there
    a way to manually construct the fetch statement once for the whole form, and have APEX be smart
    about what items get what
    return values, so that I don't have to write PL/SQL for every item? Because my query data sources
    are sometimes in remote databases, I have to write manual fetch and dml anyway. Just would like
    to streamline the process.
    Thanks,
    Carol

    HI Andy -- Well, I'd love it if this worked, but I'm unsure how to implement it.
    It seems I can't put this process in the results page (the page w/ the link, that has multiple report rows), because the link for the row will completely bypass any after-submit processes, won't it? I've tried this in other conditions; I thought the link went directly to the linked-to page.
    And, from the test of your suggestion that I've tried, it's not working in the form that allows a single row edit. I tried putting this manually-created fetch into a before header process, and it seems to do nothing (even with a hard-coded PK value, just to test it out). In addition, I'm not sure how, from this page, the process could identify the correct PK values from the report page, unless it can know something about the row that was selected by clicking on the link. It could work if all the PK columns in my edit form could be set by the report link, but sometimes I have up to 5 pk columns.
    Maybe part of the problem is something to do with the source type I have for each of the form items. With my first manual fetch process, they were all pl/sql functions. Not sure what would be appropriate if I can somehow do this with a single (page level?) process.
    Maybe I'm making this too hard?
    Thanks,
    Carol

  • How to convert colon separated column values in multiple rows in report

    Hi All,
    I want to display colon separated values from a column, in a multi row in report.
    For example i have a column1 in a table with value 'A:B:C' , column2 has value '1'.
    i want to show in a report three rows using these two columns like
    column1 column2
    A 1
    B 1
    C 1

    Here's one way:
    SQL> create table test (col1 varchar2(20), col2 number);
    Table created.
    SQL> insert all
      2    into test values ('A:B:C', 1)
      3    into test values ('Dg:Ezs', 2)
      4  select * from dual;
    2 rows created.
    SQL> select
      2    t.col2,
      3    regexp_substr(t.col1, '\w+', 1, t2.column_value) c1
      4  from test t,
      5    table(cast(multiset(select level
      6                        from dual
      7                        connect by level <= length(t.col1) - length(replace(t.col1, ':', '')) + 1
      8                       ) as sys.odcinumberlist )) t2
      9  order by 2, 1;
          COL2 C1
             1 A
             1 B
             1 C
             2 Dg
             2 Ezs
    SQL>Edited by: Littlefoot on Jan 31, 2012 10:13 AM

  • SQL Developer - Pulling column value from previous row

    I am using Oracle SQL developer and trying to pull a value from a column from the previous row.
    Currently this is an example from the code im using.
    Select CD1.nbr_dw, CD1.SEQ_DW, CD1.CDL_NET_PAID, CD1.UNITS_ALLOW,CD1.ALLOW_AMT, CD1.UNIT_PRICE, CD1.BACKED_OUT,
    case
    When CD1.NET_PAID = 0 then 0
    ****NEW CODE*****
    Else CD1.ALLOW_AMT / CD1.UNIT_PRICE
    end as NEW_UNITS
    From Table_A CD1
    join (Select nbr_dw, DET_DW, SEQ_DW
    From Table_B
    ) CD2
    on CD1.nbr_dw = CD2.nbr_dw
    I need to add another when statement that says when CD1.BACKED_OUT = 'Y' populated the NEW_UNITS field with the previous rows value of CD1.UNIT_PRICE. Note, the CD1.SEQ_DW can be used to determine the previous row. Any ideas?

    Hi,
    Welcome to the forum!
    The analytic LAG function can return a value from the previous row:
    LAG (cd1.unit_price) OVER ( -- PARTITION BY  x          -- if needed
                                   ORDER BY          cd1.seq_dw
                     )It's unclear if you need a PARTITION BY clause or not.
    "PARTITION BY x" means that you want the value from the last row that has the same value of x as the current row.
    If you omit the PARTITION BY clause, it means you want the last row regardless of what any other columns are.
    Whenever you have a problem, it ehlps if you post a little sample data (CREATE TABLE and INSERT statements) and the results you want from that data.
    Explain how you get those results from that data.
    Always say what version of Oracle you're using.

  • Concatenate multiple rows in a single column

    Hi 
    I am using Web Intelligence v4.0x (i think) and I am hoping to get help.
    My query (from Performance Management Module) has a field name called "Device Name" and it has two rows, server1 and server 2 (maximum of 33 servers)
    I am trying to concatenate these values so that a blank cell in a report reads
    "Devices are: server1, server2"
    I am not able to concatenate server1 and server2 (i.e. get server1, server2) in the above statement. I've tried to use Previous(Self) and it does not work. I get output in two rows as
    server1,
    server2,
    Any assistance or direction is appreciated.
    Thanks - Kev

    Hi Jothi,
    The solution that helped me earlier
    "VAR1 =Replace(ReportFilter([Customer]);";";",")"
    worked for one Customer ID that had two (or more) invoice# related to that Customer ID.
    If there is more than one customer ID fetched by the query, the above solution merges all the related invoice# in that variable and does not merge invoice# per Customer ID.
    E.g.
    Customer ID     Invoice ID
    0001               P100
    0001               P101
    0002               P150
    0002               P151
    Desired Output
    Customer ID     Invoice ID
    0001               P100, P101
    0002               P150, P151
    Actual Output: The query merges as:
    Customer ID     Invoice ID
    0001               P100, P101, P150, P151
    0002               P100, P101, P150, P151
    and so on till the last customer ID is fetched.
    Is it possible to tweak the query to obtain the Desired Output? Your help is appreciated.
    Thanks - Kavan

Maybe you are looking for

  • How can I stop Crystal reports from locking tables in our SQL db?  PLEASE HELP!!!

    Post Author: kevans CA Forum: Data Connectivity and SQL I really need help with this and so far I've had no luck finding a solution on Crystal's knowledge base, forums our even outside of this site. I recently upgraded from crw8 to crw10 and of cours

  • Error with plant in as01

    hi, I have defined a location within the plant. When I am assigning it to asset master (AS01) . It is giving me error message that entry does not exist in table T499S. I checked back and entry is there in the table. How to proceed on this . regards J

  • Tethering the Playbook to a Non-Blackberry Smartphone

    Warning - I'm a Tech Journalist - Whatever you say can and will be used against you I've been told that a Playbook can be tethered to most smart phones for email. Unfortunately the people who told me this weren't technical enough to be able to explai

  • Maps app missing

    Somehow, my Maps app is missing on my home screen. It only appears when I double tap the home button, and then it appears at bottom of screen with all the recently opened apps. Any way I can get it back on the home screen where it was when I bought t

  • 9210 to 9300 Data transfer

    I have just purchased a 9300 and wish to transfer all data from my old 9210. I have tried to use "Install Data Collector" on the 9300 with both communicators facing IR ports but the following error message occurs. Error while sending via Infra Red Sy