concatenate the strings in cumulative mode

Dear Experts,

I have a table that stores orders information placed by customers. It stores Customer Id, order Id, order Date, and Date sent. I need to write a sql query that gives me the previous history / order date and ship date in the format shown below. Is there more than 10 orders per customer then I need only the previous order of 10 and the shipping date.

Customer_idOrder_IDORDER_DATEShipped_Date
C1O101/01/201301/07/2013
C1O228/01/201330/01/2013
C1O318/04/201322/04/2013
C1O414/07/201316/07/2013
C1O508/02/201308/04/2013

Output:

Customer_idOrder_IDH_OrderDateH_ShippedDate
C1O1NULL VALUENULL VALUE
C1O20101201307012013
C1O328012013; 0101201330012013; 07012013
C1O418042013; 28012013; 0101201322042013; 30012013; 07012013
C1O514072013; 18042013; 28012013; 0101201316072013; 22042013; 30012013; 07012013

Before posting my question here, I tried using lead, lag and listagg functions but I am unable to frame the query that produces the result I'm looking for. Any help would be greatly appreciated.

I'm using oracle 11g.

Thank you.

You can also...

Select Customer_ID

order_id

, trim (both ';' of sys_connect_by_path (to_char (order_date, 'ddmmyyyy'),' ;')) h_order_date))

, trim (both ';' of sys_connect_by_path (to_char (Shipped_Date, 'ddmmyyyy'),' ;')) h_Shipped_Date))

Of

(select Customer_ID

order_id

lag(order_date,1,null) on order_date (order by order_id)

, lag(Shipped_Date,1,null) over (order by customer_id) Shipped_Date

row_number() over (order by order_id) rn

from your_table t

)

Start by rn = 1

connect by prior rn = rn - 1

Using the MODEL clause:

Select customer_id

order_id

rtrim (h_order_date, ';') h_order_date

rtrim (h_shipped_date, ';') h_shipped_date

t

model

partition (customer_id)

dimension (row_number() over (order by order_id) rn)

measures (order_id, order_date, shipped_date, h_order_date cast (null as varchar2 (256)), climb (null as varchar2 (256)) h_shipped_date)

rules)

h_order_date [rn > 1] order by rn = to_char (order_date [cv () - 1], 'ddmmyyyy') | « ; » || h_order_date [cv () - 1]

, h_shipped_date [rn > 1] order by rn = to_char (shipped_date [cv () - 1], 'ddmmyyyy') | « ; » || h_shipped_date [cv () - 1]

)

Tags: Database

Similar Questions

  • How to concatenate the string with a digital command?

    Hello

    How to concatenate the string with a digital command?

    Thank you.

    I think I forgot to add the semicolon, what you can do is, drag the CONCATENATE function and add semicolon.

  • concatenate the strings comand...

    sHello,

    I must repeat that channels below a large part of the time (ON SQL MORE);

    Now I do with comand of copying and pasting each string, but it is very unconfortable.

    How to concatenate the string in a string only, or max 2 strings?

    .. .so I need that I copy/past comand to do all operations of this...

    COMNAD STRING:

    create user Patrick identified by loan;

    Grant connect, create session, imp_full_database to Patrick;

    GRANT to CREATE ANY WORK to Patrick;

    modify user quota unlimited Patrick on the SYSTEM;

    grant unlimited tablespace to mx;

    THANKS FOR HELP

    sqlplus command line allows you to paste together multiple orders (lines) and it then executes sequentially.

    Hemant K Collette

  • Concatenate the strings from VISA

    Hello people,

    I'm still fairly new to LabView, please bear with me.

    I'm interested in doing a Subvi, which will receive bytes on a VISA from serial port and write each line to a greater (concatenated) string, so it can later be stored in a file. In simple terms, I want to save all the data on the serial port for 8 tests to be completed. There will be 6 cases of this in the parent VI, so he needs be modular.

    I expect a series of 8 channels of the source serial communication, each line begins with "Success" or "Failed" then the test. for example:

    Past test1

    Failure of test2

    Past of test3

    Past of test4

    .

    .

    .

    The current method I use must react when there are present bytes in the buffer in series, and then identify a match (currently it only identifies a match of 'Success').

    Is it possible to get a match for the substring to 'Success' OR 'failure '?

    How can I place all these strings on a chain? Concatenation of strings do not work because I'm having the same input string of the VI...

    Any help/input would be welcome, thank you.

    Here is a basic example of using to concatenate strings. Since it is always very difficult to know if you call your Subvi several times or if you call once and want to to read all the results I won't comment much more on it. This example would read all the results and the output format string you want to write to a file later or do whatever you want with it. The basic constructs of what you will need are illustrated here. How to encorporate in your application will be difficult to say without any code beyond the wick you have posted.

  • How to concatenate the string of normal worksheet to srting

    Hello

    I try to concatenate string worksheet to sring normal, but she cannot concatenate... here, I have attached my program for your firm .the support cannot be CONCATENATE.

    Hello

    Your channel is get concatenated but is getting added to the new line. If you exapnd your channel indicator, you can see ")" in the new line.

    Remove the \n character and you will get the desired output.

  • How do to concatenate the strings having single quote and ampersand

    Hi all

    I have a task to concatenate two columns under SID - SNAME.

    Input parameter is: sid. We can pass multiple parameters: sid

    CREATE TABLE TABLE1 (NUMBER SID, SNAME VARCHAR2 (100));

    Insert into TABLE1 (SID, SNAME) values (1, 'SURF UP');

    Insert into TABLE1 (SID, SNAME) values (2, 'GNLV STYLE & KEY');

    Insert into TABLE1 (SID, SNAME) values (3, 'ESSENTIALS NORTH & SOUTH');

    Insert into TABLE1 (SID, SNAME) values (4, "Of Ora");

    Select * from TABLE1;

    SID SNAME
    1Of THE SURF's UP
    2KEY & GNLV STYLE
    3ESSENTIALS NORTH & SOUTH
    4ORA

    Expected results

    1. with the setting entry: sid in (1,2)

    Output: 1 - SURF to the TOP, 2 - GNLV STYLE & KEY

    2. with the setting entry: sid in (1,2,3,4)

    Output: 1 - SURF to the TOP, 2 - GNLV STYLE & KEY, 3 - ESSENTIALS NORTH & SOUTH, 4 - ora

    I tried to use the below query,

    Select (select RTRIM (xmlagg (xmlelement (c, sid |')))) -' || SNAME | (",")) .extract ('/ / text()'), ',')

    AS concatenated FROM table1 where «,» | : para. ',' like '%', | SID | %') as double concat;

    What I get for output is as below:

    1 SURF & apos; S upwards, 2 - GNLV STYLE & amp; TREND

    I'm not handling apstrophe and ampersand correctly.

    Can you please help me.

    Thank you

    What I get for output is as below:

    1 - SURF to the TOP, 2 - GNLV STYLE & TREND

    I'm not handling apstrophe and ampersand correctly.

    Yes. This is what happens when you use a method that is not understood.

    The answer to your question is dependent on the version and already well covered in the FAQ.

    See 'Channel aggregation' in Re: 4. How can I convert rows to columns?

    If you are on 11.2 and beyond, use LISTAGG function.

    Regarding your present attempt, since you are extracting text() nodes on an aggregate of XMLType, the result is still a valid XMLType and therefore shows the XML characters reserved in their forms with escape sequence.

    If you want to stick with the XML approach, from 11.1, is the right way to handle this situation:

    SQL> select rtrim(
      2           xmlcast(
      3             xmlagg(
      4               xmlelement(e, sid ||' - '||sname||',')
      5             )
      6             as varchar2(4000)
      7           )
      8         , ','
      9         ) as concatenated
    10  from table1
    11  where ',' || '1,2,3' || ',' like '%,'|| sid || ',%' ;
    
    CONCATENATED
    --------------------------------------------------------------------------------
    1 - SURF'S UP,2 - GNLV STYLE & KEY,3 - ESSENTIALS NORTH & SOUTH
    

    In earlier versions, use either:

    select rtrim(
             dbms_xmlgen.convert(
               extract(
                 xmlagg(
                   xmlelement(e, sid ||' - '||sname||',')
                 )
               , '//text()'
               ).getstringval()
             , 1
             )
           , ','
           ) as concatenated
    from table1
    where ',' || :para || ',' like '%,'|| sid || ',%' ;
    

    Mun

    select rtrim(
             utl_i18n.unescape_reference(
               extract(
                 xmlagg(
                   xmlelement(e, sid ||' - '||sname||',')
                 )
               , '//text()'
               ).getstringval()
             )
           , ','
           ) as concatenated
    from table1
    where ',' || :para || ',' like '%,'|| sid || ',%' ;
    
  • concatenate the strings from a column into a single row?

    How to concatenate strings from a column into a single line?

    Color
    ------
    Red
    Orange
    Blue
    Green

    And return a set of results as follows:

    Colors
    -------------------------
    Red, orange, blue, green

    Various ways can be found here:
    http://www.Oracle-base.com/articles/10G/StringAggregationTechniques.php

  • Concatenate the strings of several lines into one line.

    Hello

    What is the name of this analytical function (or log in) which
    would return more line as a concatenated line strings. that is to say:
    (I know that it is possible using the regular functions of pipeline).
    ROW1:   STR1
    ROW2:   STR2
    ROW3:   STR3
    
    select tadah().... from ...
    
    result:
    
    ROW1: STR1 STR2 STR3
    Thank you.

    Hello

    DanielD wrote:
    Hello

    What is the name of this analytical function (or log in) which
    would return more line as a concatenated line strings. that is to say:
    (I know that it is possible using the regular functions of pipeline).

    ROW1:   STR1
    ROW2:   STR2
    ROW3:   STR3
    
    select tadah().... from ...
    
    result:
    
    ROW1: STR1 STR2 STR3
    

    The function is SYS_CONNECT_BY_PATH

  • Concatenate the strings!

    Hi all

    I do this select statement and the result is as follows:

    SQL > select 'create table ' | nom_partition | ' in select * from '. table_name | ';' from dba_tab_partitions where table_name = 'MONEY ';

    "CREATE TABLE". NOM_PARTITION | "ASSELECT * FROM ' | TABLE_NAME | « ; »
    --------------------------------------------------------------------------------
    create the table P_TAB_MONEY_200908 select * money;
    create the table P_TAB_MONEY_200909 select * money;

    But I would like the return of result without P_TAB_

    Thank you!
    Dan.
    select 'create table ' || substr(partition_name,7) || ' as select * from ' || table_name ||';' from dba_tab_partitions where table_name='MONEY';
    

    SY.

  • concatenate the strings in a dimension

    Hi, experts, if the data is stored as below in db.


    Time (DateTime) event (varchar2)
    2010-01-13 13:00 lunch
    2010-01-13 15:00 session
    2010-01-14 12:00 lunch
    2010-01-14 16:00 meeting
    2010-01-18 11:00 meeting
    2010-01-18 14:00 meeting


    How to display the data in the PivotTable view calendar

    (see http://img46.imageshack.us/img46/6994/questioni.jpg)



    S M T W T F S
    2010-01-13-14-01-2010
    lunch lunch
    Meeting meeting
    2010-01-18
    meeting
    meeting


    Thank you very much!

    Hi, try this...

    Date1 select column (which has timestamp), date2 column (which has no timestamp), the week number of the date in the year (which displays the data from 1 to 52 weeks), event, the name of the day.

    Now go to Pivot, keep the week number and date1 partly lines, part, Date2 and day probation measures are partly lables measure...
    You must define an aggregation max or min for the event rule. Here, I guess I got the timestamp column, during the hours mentioned (examples of data provided by you) that one event will be there...

    Hide column Date1 pivot.

    Instead of the Date 1 column, you can take a column that got values such as: 12 AM, 01:00, 02:00,... 23:00 (must be in the same order how day begins and ends)

    I have not check cela, but assume it will work...

  • Incorporate the binary string in the string spreadsheet file

    Hello LabVIEW wizards...

    So I use scripture to VI file spreadsheet to create a beautiful layout, tabs-delimited report of one of my programs for the acquisition of data file. In one of the cells in the resulting worksheet file that I want to put a binary string of all my control values so when you open the data file all the control parameters used for its manufacture are restored, but the string is hidden when the report is displayed in Excel.

    The problem is that the binary string flattened uses tabs and returns as part of its syntax the Spreadsheet File this VI to Write it's going in all directions. Worse yet, I can't unflatten chain when I open the file text because of "corrupt data or unexpected".

    If I concatenate the string flattened with quotes around it she is superb and is placed in a single cell in Excel, but when I open the file in LabVIEW that she is still several elements in the array. I've isolated the binary string using the file VI text reading and got a subset of the quoted string, but it still unflatten correctly.

    Essentially, I need to know how to get LabVIEW to pull a string literal full of special characters into a spreadsheet file and it unflatten. Any gurus what help you can provide is greatly appreciated.

    Thank you

    Jordan

    Jordan

    I suggest that you change the formatting of your chain shipped by replacing the tabs and returns with other characters that are not considered as commands by the spreadsheet functions. Without knowing how you represent your control binary values, I can't offer specific characters.

    If two non-printable characters exist which do not appear in the control data, it's easy: just find and replace tabs and returns with those characters.  If there is no character, then something more complex needs to be done for example to escape special characters.  Or create two subVIs - one to remove the tabs and returns before writing the string in the file and the other to restore after reading.

    Lynn

  • concatenate the data in 2 tables in a third table as well as in CONCATENATE strings

    Hello. as the title says, I wish to only concatenate the data in 2 tables in a similar third table that concatenate strings don't. All tables should be 1 d. For example, suppose that there is 1 table with the following: 1. 2; 3; 4 and table 2 with:; b; c; d. I would like a table 3 either 1 a, 2 b, 3 c, 4 d. Now this could be done easily with above mentioned concatenate strings, then table construction. but table 1 and 2 have something like 150 items. Rather painful. Any ideas?

    Hold arrays of two strings in a loop for example, concatentate the strings inside the loop and run the result réécrirait array3.

    Autoindexing manages table manipulations.

    MIke...

  • Extract the contents of an XML string in offline mode

    HI gentlemen,

    Could you help me solve this problem? I had a string of Java (see below) read in a smart German eHealth card. I have to extract the tag values and put them in local variables for further processing in my Java module. How to move forward without connecting to a database, it is enough to analyze the source - the string variable? Note that the lines are separated by only 0x0A.
    <?xml version="1.0" encoding="ISO-8859-15" standalone="yes"?>
    <UC_PersoenlicheVersichertendatenXML CDM_VERSION="5.1.0" xmlns="http://ws.gematik.de/fa/vsds/UC_PersoenlicheVersichertendatenXML/v5.1">
        <Versicherter>
            <Versicherten_ID>X110101627</Versicherten_ID>
            <Person>
                <Geburtsdatum>19840717</Geburtsdatum>
                <Vorname>Johanna</Vorname>
                <Nachname>Düsterbehn</Nachname>
                <Geschlecht>W</Geschlecht>
                <StrassenAdresse>
                    <Postleitzahl>93055</Postleitzahl>
                    <Ort>Regensburg</Ort>
                    <Land>
                        <Wohnsitzlaendercode>D</Wohnsitzlaendercode>
                    </Land>
                    <Strasse>Sulzfeldstraße</Strasse>
                    <Hausnummer>7</Hausnummer>
                </StrassenAdresse>
            </Person>
        </Versicherter>
    </UC_PersoenlicheVersichertendatenXML>
    Thank you very much for your help,
    sincere friendships of

    Miklós HERBOLY
    java.lang.NoClassDefFoundError: XpathSampleClass (wrong name: XPathSampleClass)
    

    If you use my code sample in extenso, the class is named 'XPathSampleClass' (capital P), and of course the .class file must have the same name.

  • Concatenate and split the string

    Hi all

    Is there some how we can split the string like this "1 | ~ | Diego | Maradona | ~ | Footballer | The Argentina.

    in the table of 3 elements: '1', ' Diego | Maradona', ' football '. The Argentina.

    Here is my code
    public static void main(String args[]){
              System.out.println("========USE SPLIT========== " );
                   String data = "1 |~| Diego|Maradona |~| Footballer|Argentina";
                 String[] items = data.split(" |~| ");
                 for (String item : items)
                 {
                      System.out.println("item = " + item);
                 }
                 StringTokenizer tok = new StringTokenizer(data," |~| ");
                 System.out.println("========USE TOKENIZER========== " );
                 while(tok.hasMoreElements()){
                      System.out.println("item = " + tok.nextToken());
                 }
              
         }
    and put it is:
    = USE SPLIT =.
    Item = 1
    Item = |
    Item = |
    Item = Diego | Maradona
    Item = |
    Item = |
    Item = football | Argentina
    = USE TOKENIZE =.
    Item = 1
    Item = Diego
    Item = Maradona
    Item = footballer
    Item = Argentina

    Published by: mycoffee on February 1, 2011 06:49

    Split() takes a regular expression. ' | ' has a special meaning in regular expressions.

    Try to use

    " \\|~\\| "
    

    as the argument of split()

  • My indicator shows only the first line of the string

    Hi all

    I'm having some trouble with chains, could you help me?

    I use a device connected to my computer in a RS-232 port.

    I configured the VISA series correctly. When I write a command to my device, the answer is something like this:

    "XXXXX."

    YYYYYY

    2222

    44444

    WWWW.

    The problem is when I try to read this response. The channel indicator shows only one line at a time every single loop. And the other orders received are stored in the buffer until their time to be displayed to come. I mean:

    In the first loop device XXXXX responses.

    In the second loop the device responds YYYYYY but now I stored what must appear:

    2222

    44444

    WWWW

    XXXXX

    YYYYYY

    2222

    44444

    WWWW

    In the third loop, the device responds 2222 and stores again:

    44444

    WWWW

    XXXXX

    YYYYYY

    2222

    44444

    WWWW

    XXXXX

    YYYYYY

    2222

    44444

    WWWW

    How can I configure my blocks to display the full string?

    Thank you

    Murilo

    Post your code and we can better understand what is happening.

    My first is however you spend only the corrent, reading of the indicator.

    You use a chain shift reg with a knot to concatenate a String?

    Your zip code and we'll have a glance.

Maybe you are looking for

  • How can I disable admin for guest?

    I am the administrator and used the user prompted for my work. I looked at the settings and given one to use as an administrator and lost all my info in the comments. I want to just hand it to the guest user to where he was before foolishly, I played

  • My mac says "Looking for printer.

    I bought D110a yesterday, and after a few soft not to install this printer on my Mac (OS X 10.6.4), I finally got to print... However, not always. By 'not always' I mean a point print at a time, through "reboot" the printer between the prints. If I d

  • I do not have iPhoto

    Hello I have a MacBook Air 11 '' and my operating system is OS X El Capitan 10.11.3 and iPhoto doesn't seem to be on my MacBook. I have searched on the AppStore but couldn't find it. How can I download it?

  • Need XP for Satellite Pro A60 display driver

    My PC in safe mode when on game sites is now and I'm having truble locate the driver.I need help laocating and installation which I new complettely instead.

  • Satellite P10 804: Toshiba Power Options - how to disable Hibernation

    Model SP10 - 804 How to turn off the Hibernation feature? The 'Enable Hibernation' box is checked and grayed out so I can't uncheck it!I don't use this feature and would like to delete the hiberfil.sys file that is beyond 1 GB. I understand that by d