Unable to retrive the data using self join

I am trying to find the time taken to close a ticket. The ticket goes through various stages: NEW, INPROCESS, CLOSED, REOPENED. If the ticket is reopened then the next stage would be INPROCESS and then CLOSED.
The CC_TICKET_INFO table contains information about the last stage of the ticket. CC_TICKET_HISTORY table contains information about all the stages of the ticket.
The challenge here is if the ticket is reopened then it should be counted as 2 instances instead of 1.
First instance from stages: NEW --> INPROCESS --> CLOSE
Second instance from stages: REOPEND --> INPROCESS --> CLOSE.
Follwoing SQL is to generate the data:
CREATE TABLE CC_TICKET_INFO
  TICKET_ID VARCHAR2(20 BYTE) NOT NULL
, TICKET_STATUS VARCHAR2(60 BYTE)
, created_date timestamp(6)
, LAST_CHANGED timestamp(6)
, ASSIGNED_TO VARCHAR2(20)
, CONSTRAINT PK_CC_TICKET_INFO PRIMARY KEY
    ticket_id
CREATE TABLE CC_TICKET_HISTORY
  TICKET_ID VARCHAR2(20 BYTE) NOT NULL
, TICKET_STATUS VARCHAR2(60 BYTE)
, CREATED_DATE TIMESTAMP(6) NOT NULL
, ASSIGNED_TO VARCHAR2(255 BYTE)
, CREATED_BY VARCHAR2(60 BYTE)
, CONSTRAINT PK_CC_TICKET_HISTORY PRIMARY KEY
    TICKET_ID
  , CREATED_DATE
insert into cc_ticket_history values ('D21207155', 'NEW', '6/28/2013 17:28:59', null, 'jsg-st');
insert into cc_ticket_history values ('D21207155', 'INPROCESS', '6/28/2013 17:48:19', 'ah-eg', 'ah-eg');
insert into cc_ticket_history values ('D21207155', 'CLOSED', '6/28/2013 18:54:23', 'ah-eg', 'ah-eg');
insert into cc_ticket_history values ('D21207155', 'REOPENED', '7/2/2013 19:55:04', 'ah-eg', 'jsg-st');
insert into cc_ticket_history values ('D21207155', 'INPROCESS', '7/2/2013 20:11:17', 'sr-eg', 'sr-eg');
insert into cc_ticket_history values ('D21207155', 'CLOSED', '7/2/2013 23:06:16', 'sr-eg', 'sr-eg');
insert into CC_TICKET_INFO values ('D21207155', 'CLOSED', '6/28/2013 17:28:59', '7/2/2013 23:06:16', 'sr-eg');
I want to find the time difference betwen '6/28/2013 18:54:23' and '6/28/2013 17:28:59' (First instance)
and between '7/2/2013 23:06:16' and '7/2/2013 19:55:04' (Second instance)
The closest I am getting is the through this query:
select L.ticket_id, L.CREATED_DATE, R.CREATED_DATE as close_date, L.TICKET_STATUS, R.TICKET_STATUS from cc_ticket_history L RIGHT join cc_ticket_history R on (L.rowid < R.rowid) where (L.TICKET_STATUS = 'NEW' AND R.TICKET_STATUS ='CLOSED') OR (L.TICKET_STATUS = 'REOPENED' AND R.TICKET_STATUS ='CLOSED');
Can it be done through SQL?

select ticket_id,ticket_status,created_date,
       case when ticket_status = 'CLOSED'
             and lead(ticket_status) over (partition by ticket_id order by created_date) = 'REOPENED'
            then lead(created_date) over (partition by ticket_id order by created_date) - created_date
            when ticket_status = 'REOPENED'
             and lag(ticket_status) over (partition by ticket_id order by created_date) = 'CLOSED'
            then created_date - lag(created_date) over (partition by ticket_id order by created_date)
       end time_difference
  from cc_ticket_history
where ticket_status in ('CLOSED','REOPENED')
TICKET_ID
TICKET_STATUS
CREATED_DATE
TIME_DIFFERENCE
D21207155
CLOSED
28-JUN-13 06.54.23.000000 PM
+000000004 01:00:41.000000
D21207155
REOPENED
02-JUL-13 07.55.04.000000 PM
+000000004 01:00:41.000000
D21207155
CLOSED
02-JUL-13 11.06.16.000000 PM
Regards
Etbin

Similar Messages

  • Unable to Save the Data Using BexSetData

    Hi All,
    I have a issue regarding saving plan data,
    Design: I  got a Workbook with several tabs, each tab has a input ready Query and has a layout as below
    A formatted user facing worksheet containing; an area where the user enters their plan data with a BEx save data button, an input ready query and a worksheet containing the BExSetData formulas that reference the values entered on the user facing worksheet.
    Issue: When i try to enter the value in the user facing sheet, the data is shown in the BexSet Data Sheet with out any problem,
    But when i try to save the data the data is not saved into the cube.
    Can any one please give some ideas of possible cause.
    One more question is the input ready query doesn't have any references to other sheets, will this be a reason for the data not saved?
    Please through some ideas.
    Thanks
    GC

    Hello,
    I think it is problem with the buffer:
    Check the notes 1136163, 1138864, 1146957, 1179076.
    please check the below;
    Delta buffer query in RSRT for BI-IP ("<infoprovider>/!!1<infoprovider>)
    Planning query donu2019t show the current data
    Thanks.
    With regards,
    Anand Kumar

  • Unable to Get the Data Using For All Entries

    Hi everybody, i am using for all entries in a program. but when i am writing a code using for all entries i am getting an error as 
    Where condition does not refers to the FOR ALL ENTRIES tables...
    SELECT KUNNR
           NAME1
           ORT01
           LAND1
       FROM KNA1 INTO TABLE ITAB1 WHERE KUNNR IN S_KUNNR.
    IF NOT ITAB1 IS INITIAL.
    SELECT VBELN
            ERDAT
            KUNNR
       FROM VBAK INTO TABLE ITAB2 FOR ALL ENTRIES IN ITAB1 WHERE KUNNR = IT_KNA1-KUNNR.
    ENDIF.
    can anybody help out in this
    regards
    hyder ali

    The correct one may be like this:
    SELECT KUNNR
    NAME1
    ORT01
    LAND1
    FROM KNA1 INTO TABLE ITAB1 WHERE KUNNR IN S_KUNNR.
    IF NOT ITAB1 IS INITIAL.
    SELECT VBELN
    ERDAT
    KUNNR
    FROM VBAK INTO TABLE ITAB2 FOR ALL ENTRIES IN ITAB1 WHERE KUNNR = ITAB1-KUNNR. "modified here
    ENDIF.
    Edited by: XuJian84 on Mar 9, 2010 4:25 AM

  • How to achieve parent-child relationship using self join?

    my table structure is as follows
    parent child name
    -1     1     A1
    1     2     A2
    1     3     A3
    how to achieve the hierarchy model using self join. this can be easily achieved using "connect by prior". but how to achieve the same using self join?

    Hi,
    Yes, that's definitely possible. If you only need to display two levels from the hierarchy, a self-join is a good option. Make it an outer join if you need to show everyone on one level, regardless of whether they have a match on the other level or not; for example, if you want the output:
    child_name     child_id     parent_name     parent_id
    A1          1
    A2          2          A1          1
    A3          3          A1          1It's good that you posted some sample data. Now post the results you want from that data, and your query (what you think is the best attempt you've made so far). If you haven't tried anything so far, then look at some other simple self-join to get ideas.

  • Error while sending the data using input schedule

    Dear Friends,
    I am unable to send the data using input schedule due to following error is occur while sending the data.
    The Error Message : Member (H1) of dimension (ENTITY) is not a base member (parent or formula)
    Can anyone please help me to resolve the above error.
    Thanks and regards,
    MD.

    Hi,
    You are trying to send data to a parent/node, you can only send data in BPC to lowest-level children (base mamabers) of any dimension.
    "H1" is a parent in the entity dimension so you should try sending to a child.
    Tom.

  • Unable to load the data into Cube Using DTP in the quality system

    Hi,
    I am unable to load the data from PSA to Cube using DTP in the quality system for the first time
    I am getting the error like" Data package processing terminated" and "Source TRCS 2LIS_17_NOTIF is not allowed".
    Please suggest .
    Thanks,
    Satyaprasad

    Hi,
    Some Infoobjects are missing while collecting the transport.
    I collected those objects and transported ,now its working fine.
    Many Thanks to all
    Regards,
    Satyaprasad

  • Oracle query with out using self join

    hi friends,
    i have one table for exeample PERSTATUS
    pk/fK STUDENT NUMBER SUBJECT MARKS STATUS
    1 ACCOUNTS 15 RED
    1 MATHS 35 YELLOW
    1 SCINECE 45 GREEN
    2 ACCOUNTS 55 BROWN
    2 MATHS 35 YELLOW
    2 SCINECE 45 GREEN
    3 ACCOUNTS 15 RED
    3 MATHS 35 YELLOW
    3 SCINECE 45 GREEN
    i want students how status is both red and yellow so i am using self join
    i want students status is both red and yellow so i am using self join
    SELECT PS.STUDENTNUMBER,PS.STATUS,PS.STATUS1 FROM PERSTATUS PS ,PERSTATUS PS1
    WHERE PS.STUDENTNUMBER-PS1.STUDENTNUMER
    PS.STATUS='RED' AND PS1.STAUTS='YELLOW'
    i want students status is both RD and YELLOW AND GREEN so i am using self join( two self joinS}
    SELECT PS.STUDENTNUMBER,PS.STATUS,PS.STATUS,PS2.STATUS FROM PERSTATUS PS ,PERSTATUS PS1,PERSTATUS PS2
    WHERE PS.STUDENTNUMBER-PS1.STUDENTNUMER AND PS.STUDENTNUMBER-PS2.STUDENTNUMBER
    PS.STATUS='RED' AND PS1.STAUTS='YELLOW' AND PS2.STAUTUS='GREEN'
    if i require MORE STATUS then more self joins required, is there any alternative to achive this
    and if results comes in multiple rows are accepted (since with the above query result will come in single row)
    i tried to use group by (studentnumber,status) with status='red' and status='yellow'
    but it is not possible could you povidet he solution

    Hi,
    Whenever you have a problem, please post CREATE TABLE and INSERT statements for your sample data, and the exact results you want from that data. Explain how you get those results from that data.
    See the forum FAQ {message:id=9360002}
    Here's an example of how to post the sample data:
    CREATE TABLE     perstatus
    (       studentnumber     NUMBER
    ,     subject          VARCHAR2 (10)
    ,     marks          NUMBER
    ,     status          VARCHAR2 (10)
    INSERT INTO perstatus (studentnumber, subject,    marks, status)
           VALUES           (1,           'ACCOUNTS', 15,       'RED');
    INSERT INTO perstatus (studentnumber, subject  ,  marks, status)
           VALUES           (1,           'MATHS',        35,       'YELLOW');
    INSERT INTO perstatus (studentnumber, subject,    marks, status)
           VALUES           (1,           'SCINECE',  45,       'GREEN');
    INSERT INTO perstatus (studentnumber, subject,    marks, status)
           VALUES           (2,           'ACCOUNTS', 55,       'BROWN');
    INSERT INTO perstatus (studentnumber, subject  ,  marks, status)
           VALUES           (2,           'MATHS',        35,       'YELLOW');
    INSERT INTO perstatus (studentnumber, subject,    marks, status)
           VALUES           (2,           'SCINECE',  45,       'GREEN');
    INSERT INTO perstatus (studentnumber, subject,    marks, status)
           VALUES           (3,           'ACCOUNTS', 15,       'RED');
    INSERT INTO perstatus (studentnumber, subject  ,  marks, status)
           VALUES           (3,           'MATHS',        35,       'YELLOW');
    INSERT INTO perstatus (studentnumber, subject,    marks, status)
           VALUES           (3,           'SCINECE',  45,       'GREEN');You were on the right track, thinking about GROUP BY. You're interested in something about the whole group of rows that has the same studentnumber. Looking at any individual row won't tell you if that row is part of the group you're interested in or not.
    If you want to see information about the group as a whole, you can do the whole job with GROUP BY. In this case, studnetnumber is the only thing that an entire group has in common. If you wanted to see the studentnumbers that had both RED and YELLOW, that is:
    STUDENTNUMBER
                1
                3here's one way you could do it:
    SELECT       studentnumber
    FROM       perstatus
    WHERE       status     IN ('RED', 'YELLOW')
    GROUP BY  studentnumber
    HAVING       COUNT (DISTINCT status) = 2  -- That is, both RED and YELLOW
    ORDER BY  studentnumber
    ;But say you wanted to see details about individuals in the group; for example, say we want to see all the columns for students that have all 3 of RED, YELLOW and GREEN, like this:
    STUDENTNUMBER SUBJECT         MARKS STATUS
                1 SCINECE            45 GREEN
                1 ACCOUNTS           15 RED
                1 MATHS              35 YELLOW
                3 SCINECE            45 GREEN
                3 ACCOUNTS           15 RED
                3 MATHS              35 YELLOWWe used the aggregate COUNT function earlier, but aggregate functions require collapsing the results down to one row per group.
    However, most of the aggregate functions, like COUNT, have analytic counterparts, that can give the same results without collapsing the result set. Here's one way to get the results above, using the analytic COUNT function:
    WITH     got_cnt          AS
         SELECT  studentnumber, subject, marks, status
         ,     COUNT ( DISTINCT CASE
                                   WHEN  status  IN ('RED', 'YELLOW', 'GREEN')
                             THEN  status
                               END
                    ) OVER (PARTITION BY  studentnumber)     AS cnt
         FROM    perstatus
    SELECT    studentnumber, subject, marks, status
    FROM       got_cnt
    WHERE       cnt  = 3
    ORDER BY  studentnumber
    ,            status
    ;

  • Unable to change the data in PSA

    Hello All,
    I have a delta failure because of invalid characters in one of the field and now i wanted to change the PSA. I have deleted the request from all data targets and started changing the error record, it is not showing all columns from PSA hence i am unable to change the data in required field.
    Could you please let me know how will i see all columns from PSA. Thanks
    Regards,Ashok

    Hi Ashok,
    To increase/decrease the number of columns that are displayed on the menu from the Settings option select Change display variants
    Also if you want to see say all the failed records you can sort the order of the data using the Status column

  • Unable to access the data from Data Management Gateway: Query timeout expired

    Hi,
    Since 2-3 days the data refresh is failing on our PowerBI site. I checked below:
    1. The gateway is in running status.
    2. Data source is also in ready status and test connection worked fine too.
    3. Below is the error in System Health -
    Failed to refresh the data source. An internal service error has occurred. Retry the operation at a later time. If the problem persists, contact Microsoft support for further assistance.        
    Error code: 4025
    4. Below is the error in Event Viewer.
    Unable to access the data from Data Management Gateway: Query timeout expired. Please check 1) whether the data source is available 2) whether the gateway on-premises service is running using Windows Event Logs.
    5. This is the correlational id for latest refresh failure
    is
    f9030dd8-af4c-4225-8674-50ce85a770d0
    6.
    Refresh History error is –
    Errors in the high-level relational engine. The following exception occurred while the managed IDataReader interface was being used: The operation has timed out. Errors in the high-level relational engine. The following exception occurred while the
    managed IDataReader interface was being used: Query timeout expired. 
    Any idea what could have went wrong suddenly, everything was working fine from last 1 month.
    Thanks,
    Richa

    Never mind, figured out there was a lock on SQL table which caused all the problems. Once I released the lock it PowerPivot refresh started working fine.
    Thanks.

  • The ADO NET Source was unable to process the data. ORA-64203: Destination buffer too small to hold CLOB data after character set conversion.

     We developed a SSIS Package to pull the data From Oracle source to Sql Server 2012. Here we used ADO.Net source to pull the records from Source but getting the below error after pulling some 40K records.
      [ADO NET Source [2]] Error: The ADO NET Source was unable to process the data. ORA-64203: Destination buffer too small to hold CLOB data after character set conversion.
    [SSIS.Pipeline] Error: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED. 
     The PrimeOutput method on ADO NET Source returned error code 0xC02090F5. 
     The component returned a failure code when the pipeline engine called PrimeOutput(). 
    The meaning of the failure code is defined by the component, 
    but the error is fatal and the pipeline stopped executing. 
     There may be error messages posted before this with more 
    information about the failure.
    Anything that we can do to fix this?

    Hi,
      Tried both....
      * Having schema type as Nvarchar(max). - Getting the same error.
      * Instead of ADO.Net Source used OLEDB Source with driver as " Oracle Provide for OLE DB" Getting error as below.
           [OLE DB Source [478]] Error: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80004005.
           [SSIS.Pipeline] Error: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED.  The PrimeOutput method on OLE DB Source returned error code 0xC0202009.  The component returned a failure
    code when the pipeline engine called PrimeOutput(). The meaning of the failure code is defined by the component, but the error is fatal and the pipeline stopped executing.  There may be error messages posted before this with more information about the
    failure.
    Additional Info:
       * Here the Source task is getting failed not the conversion or destination task.
    Thanks,
    Loganathan A.

  • Unable to get the data when capture the BOL object infomation.

    Hello All.
    I created a Z component.
    In that component I created one View.
    In that view i have the context node with BOL object  -  BTAdminH
    In configuration also i am selecting the fields.
    But I am unable to capture the data.
    In that i write like
    data: lr_ent type ref to CL_CRM_BOL_ENTITY.
    lr_ent ?= me->typed_context->btadminh->collection_wrapper->get_current( ).
    I write this code in the EDIT button event.
    But lr_ent is not capture any value.
    BTADMINH is there in the CTXT class.
    In debugging GET_CURRENT( ) method
    me->collection_ref->collection
    is not having any value.
    I do not know why it is not having any value.
    When I am using value node it is working fine.
    But when i am using BOL object at that time only it is not getting any value.
    Can anybody give me suggision to solve this problem.
    In stadard it is working fine.
    How it is working in Stadard i did not understand.
    Why it is not working in Z component.
    How we can use BOL objets in Z components.
    Please give me some solution.
    Regards,
    B. Krishna.

    Hi krishna
    Is this a Z component to be used within a  standard component?
    ->then you need to create a usage definition to this component from standard
    ->expose btadminh as public context through component controller
    ->create binding to the standard btadminh through the usage initialize method
    then it should be okay
    If the Z component is standalone , then create Root object BTorder and BTAdminH node should having a hierarchial relationship to this. Initialize BTOrder through cl_crm_bol_core methods.

  • BOFC Unable to start the data source

    Hi there,
    i've done a standalone install using SQL 2008 R2 express. But i'm unable to start the data source and get this error:
    Failed to start data source
    Failed to start server instances on machine DELL1.
    Failed to initialize server configured on machine DELL1.
    Class not registered
    Thanks,
    Anees

    Ok, problem solved.
    I had to create a seperate DCOM user and assign it to the following roles in windows:
    log on as a batch job
    log on as a service
    then assign this DCOM user to the Ctbroker and CTserver. As i'm not running this on a domain, there was no need to use 'packet level authentication'. So i set the authentication level to none.
    There was no need to use the web based admin interface. Ctadmin.msc worked perfectly.
    Thanks,
    Anees

  • Unable to change the data source of SAP system

    Dear all,
    We have install SAP netweaver EHP1 standalone java on oracle 10.2.0.5 on windows 2008 R2.
    while installation i have given the central SLD system as solman,
    By mistake i have deleted the system from SMSY.. now when i createed the system manually i am unable to change the data resource as SLD due to this i can start my SMD configuration
    Request please let me know how to resolve this issue.
    Thanks
    Paresh

    Hi Paresh,
    You can proceed with deleting your SAP system from SMSY (along with connected technical content such as AS Java definition) and the run the LANDSCAPE FETCH through transaction SMSY_SETUP to have the correct definition of your SAP system in SMSY.
    Following this, you could use the addon Landscape Verification (a new thing I learnt today!!!)  to check the correctness of transaction SMSY. The following link details the Landscape verification 1.0 for SolMan:
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/e093b3ce-c034-2d10-01bc-b51f1691d3da?quicklink=index&overridelayout=true
    Hope this helps sort out your issue.

  • Unable to find the data source in r/3  ECC 6.0 -  ( 0FI_GL_10 ) in RSA5

    Hi guys,
    I am unable to find the data source(0FI_GL_10) in RSA5.
    Presently I am using BI7.0 version with R/3 ECC 6.0.
    BI Patch level - 16.
    BI content Patch level - 8
    Thanks,
    Gupta

    Hi,
    Try Installing Application Component Hierarchies 
    http://help.sap.com/saphelp_nw2004s/helpdata/en/b3/c30a0e9c44204eb596c6353c827d2e/frameset.htm
    Use RSA9 for this.
    Hope this helps.
    Thanks,
    JituK

  • Excel 2013 PowerPivot Error - "PowerPivot is unable to load the Data Model"

    I'm attempting to use the PowerPivot add-on in Excel.  When clicking 'Manage Data Model' or attempting to 'Load to data model,' I receive the error 'We couldn't load the Data Model.  This may be because the Data Model in this workbook is damaged.',
    followed by 'PowerPivot is unable to load the Data Model.'  This happens irrespective of data source type.  I have Excel 2013 32-bit, PowerPivot 32-bit, running on Windows 7 OS 64-bit.  I am not running an SSAS instance on my machine. 
    Any suggestions?

    Hi
    Have you ever tried to repair your office?
    Also we may refer to the following blog :
    http://blogs.technet.com/b/the_microsoft_excel_support_team_blog/archive/2013/11/12/powerpivot-for-excel-2013-errors-after-october-update-kb-2825655.aspx
    This issue seems to be caused by the October 2013 update (KB 2825655) for Excel 2013. Try to remove it or restore the system to an earlier point and check the result.
    Regards
    Tylor Wang
    TechNet Community Support

Maybe you are looking for

  • Error in the creation of function module

    hi,         pls help me i am getting the error "Only tables with simple line structure are   allowed in RFC" pls give me solution to solve this problem.

  • Windows 7 x64 on T400s

    I've now been using Windows 7 RTM x64 on my T400s for about a week and just wanted to document my findings. Windows is generally running quite fast and stable on the new ThinkPad, although there are certain outstanding issues, most of which I guess w

  • 6 Buttons do not function on Satellite U400-10O after upgrading to Vista Ultimate

    Hi, I have upgraded my U400-10O from original Win Vista Home Premium to Vista Ultimate, installed each and every driver and utility program, (some of them, e.g. TVAP several times ;-) However could not succeed to operate the multimedia shortcut butto

  • How to update vbak,vbap in MV45AFZZ

    DATA:  lw_WZEIT TYPE marc-WZEIT,             lw_date  type sy-datum. LOOP at XVBAP where PSTYV = 'ZRET'. SELECT single WZEIT          into lw_WZEIT          from marc         where matnr = xvbap-matnr. IF sy-subrc = 0.     lw_date = lw_WZEIT + sy-dat

  • How to remove gray line around an empty image in DW CS6

    I have an image that I retrieve from a database (the path) files are stored in a folder. However when there is no image the image outline is still there. I have managed to remove the image dreamweaver CS6 gives you automatically (if there is an error