Dear Experts,
I have a table that stores orders information placed by customers. It stores Customer Id, Order Id, Order Date and Shipped Date. I need to write a sql query that gives me the previous/history of order date and shipped date in this format shown below.If there are more than 10 orders per customer then I only need the previous 10 order and shipped date.
Customer_ID | Order_ID | Order_Date | Shipped_Date |
C1 | O1 | 1/1/2013 | 7/1/2013 |
C1 | O2 | 28/01/2013 | 30/01/2013 |
C1 | O3 | 18/04/2013 | 22/04/2013 |
C1 | O4 | 14/07/2013 | 16/07/2013 |
C1 | O5 | 2/8/2013 | 4/8/2013 |
Output:
Customer_ID | Order_ID | H_OrderDate | H_ShippedDate |
C1 | O1 | NULL | NULL |
C1 | O2 | 01012013 | 07012013 |
C1 | O3 | 28012013;01012013 | 30012013;07012013 |
C1 | O4 | 18042013;28012013;01012013 | 22042013;30012013;07012013 |
C1 | O5 | 14072013;18042013;28012013;01012013 | 16072013;22042013;30012013;07012013 |
Before posting my question here, I have tried using lead, lag and listagg functions but i'm unable to frame the query that gives the output I am looking for. Any help would be greatly appreciated.
I am using oracle 11g.
Thank You.