calculate the time difference between several lines

Hello

I have a table as below:

create table select TEST_CASETBL (ID, CASE_NUM, CASE_STATUS, CASE_SUB_STATUS, LAST_UPD_DTTM)

112, 123-456', 'open', 'Work', TO_DATE (11 March 2015 13:00 ',' dd/mm/yyyy hh24:mi:ss') of the DUAL union all select

113, 123-456', 'Open', 'pending on the admin', TO_DATE (10 January 2015 15:00 ',' dd/mm/yyyy hh24:mi:ss') of the DUAL union all select

114, 123-456', 'Open', 'client expectation', TO_DATE (10 July 2015 09:00 ',' hh24:mi:ss' of dd/mm/yyyy) of the DUAL union all select them

315, 123-456', 'open', 'Work', TO_DATE (September 15, 2015 10:00 ',' dd/mm/yyyy hh24:mi:ss') of the DUAL union all select

219, 123-456', 'Open', 'pending on the admin', TO_DATE (January 9, 2015 08:00 ',' dd/mm/yyyy hh24:mi:ss') of the DUAL union all select

651, 123-456', 'open', 'Work', TO_DATE (August 20, 2015 10:00 ',' dd/mm/yyyy hh24:mi:ss') from DUAL;

I would like to calculate the duration total (days ideally) to CASE_SUB_STATUS, so have a set of lines:

CASE_NUM of work waiting on admin waiting on customer

-------------------------------------------------------------------------------------------------------------------------------------------------------

123-456 70days 6 hours

Here is the explanation of the pattern:

ex: for everyday business computing (timestamp timestamp of ID:651 - ID:219) +(timestamp of ID:315-timestamp of ID:114) + (ID:112 stamp - current_time) = 11 days + 21 days 22hrs 23hrs 36 days 9 hours

still waiting on admin

(ID:219 timestamp - timestamp of ID:315) + (ID:113 timestamp - timestamp of ID:112)

still waiting on the client

(ID:114 timestamp - timestamp of ID:113)

I would appreciate any idea how to solve this, ideally as an SQL

Thank you

Should he not?...

with test_casetbl (id, case_num, case_status, case_sub_status, last_upd_dttm) as)

Select 112, 123-456', 'Open', 'Work', TO_DATE (11 March 2015 13:00 ',' dd/mm/yyyy hh24:mi:ss') of all the DOUBLE union

Select 113, 123-456', 'Open', 'pending on the admin', TO_DATE (10 January 2015 15:00 ',' dd/mm/yyyy hh24:mi:ss') of all the DOUBLE union

Select 114, 123-456', 'Open', 'client expectation', TO_DATE (10 July 2015 09:00 ',' dd/mm/yyyy hh24:mi:ss') of all the DOUBLE union

Select 315, 123-456', 'Open', 'Work', TO_DATE (September 15, 2015 10:00 ',' dd/mm/yyyy hh24:mi:ss') of all the DOUBLE union

Select 219, 123-456', 'Open', 'pending on the admin', TO_DATE (January 9, 2015 08:00 ',' dd/mm/yyyy hh24:mi:ss') of all the DOUBLE union

Select 651, 123-456', 'Open', 'Work', TO_DATE (August 20, 2015 10:00 ',' the hh24: mi: ss' dd/mm/yyyy) double

),

t like)

Select case_num,

case_sub_status,

(last_upd_dttm, 1, sysdate) ahead of diff last_upd_dttm (partition by order of last_upd_dttm case_num).

of test_casetbl

)

Select case_num,

trunc (a) | "day (s). TO_CHAR (date ' 1-1-1' + a, "fmhh24" 'mi' minute (s) "ss" second (s) hour (s)"") "work."

trunc (b) | "day (s). TO_CHAR (day 1-1-1' + b, "fmhh24" 'mi' minute (s) "ss" second (s) hour (s)"") 'Waiting on admin',

trunc (c) | "day (s). TO_CHAR (day 1-1-1' + c, "fmhh24" 'mi' minute (s) "ss" second (s) hour (s)"") "waiting on customer."

t

pivot)

Sum (diff)

for case_sub_status in)

'Work' is.

B "waiting on admin',

C "customer expectation."

)

)

CASE_NUM Working Waiting on admin Waiting on customer
123-456 63 day (s) 22 hour (s) (s) 50 minute 49 second (s) 19 day (s) on 20 (s) hour 0 minute 0 second (s) 27 day (s) on 4 hour (s) 0 minute 0 second (s)

Tags: Database

Similar Questions

  • Calculation of the time differences between several lines

    Hello

    I have a table as below:

    EVENT ID DATE
    1. start 05/03/2012-13:00
    1. stop the 15:00 05/04/2012
    1. start 09:00 05/07/2012
    1 stop on 05/09/2012 10:00
    Start 2 08/06/2012-08:00
    2 stop on 08/07/2012 10:00

    I would like to calculate the duration (in hours ideally) between 'Start' and 'Stop' for each ID, so having a set of lines:

    ID TimeSpan
    ---------------------
    1 75
    26 2

    I would appreciate any idea how to solve this, ideally as a SQL solution or maybe a function.

    Thank you very much!
    Tom

    The difference between two dates is a number, where 1 = 1 day. Multiply by 24 to get hours.

    Use the LAG, as stated above, to compare the date prior to the current date.

    create table T(TID, EVENT, TDATE) as select
    1, 'start', TO_DATE('03/05/2012 13:00:00', 'dd/mm/yyyy hh24:mi:ss') from DUAL union all select
    1, 'Stop',  TO_DATE('04/05/2012 15:00:00', 'dd/mm/yyyy hh24:mi:ss') from DUAL union all select
    1, 'start', TO_DATE('07/05/2012 09:00:00', 'dd/mm/yyyy hh24:mi:ss') from DUAL union all select
    1, 'Stop',  TO_DATE('09/05/2012 10:00:00', 'dd/mm/yyyy hh24:mi:ss') from DUAL union all select
    2, 'start', TO_DATE('06/08/2012 08:00:00', 'dd/mm/yyyy hh24:mi:ss') from DUAL union all select
    2, 'Stop',  TO_DATE('07/08/2012 10:00:00', 'dd/mm/yyyy hh24:mi:ss') from DUAL;
    
    select tid, round(sum(hours)) hours from (
      select case
        when EVENT = 'Stop' then 24*(TDATE - LAG(TDATE) over(partition by TID order by TDATE))
        else 0 end hours,
      TID from T
    )
    group by tid;
    
    TID HOURS
    --- -----
      1    75
      2    26
    
  • Is there an easy way to calculate the time difference?

    I am trying to find a way to calculate the time difference between

    here at a certain time

    var settime:Number = 02:35

    and

    now would be getDate();

    I tried something rediculus, but it does not work when I entered a date less than 24 hours, is there a class out there who can just this kind of things

    or y at - it something on the internet that could tell me the difference between different time

    Thank you

    My attempt

    var date: Date = new Date();

    Set timer to what would I like to call the function
    var lastcallH:Number = 22;
    var lastcallM:Number = 50;
    var lastcallS:Number = 0;

    Set up of the 24-hour clock
    var tHour:Number = 24;
    var tMinute:Number = 60;
    var tSecond:Number = 60;

    Get the current time
    var cHour:Number = date.getHours ();
    var cMinutes:Number = date.getMinutes ();
    var cSeconds:Number = date.getSeconds ();

    Set the first variable
    var fH:Number;
    var fM:Number;
    var fS: Number;

    A second set of Variable
    var sH: number;
    var sM:Number;
    var sS:Number;

    Final conversion for the Timer
    var finalMil:Number;

    Time variables that will need to be converted

    If (lastcallH < Thur)
    {
    fH = chorus - Thur;
    fM = cMinutes - tMinute;
    fS = cSeconds - tSecond.
    finalMil = (sH * 60) + (sM * 60) + (sM * 60);
    }
    ElseIf (cMinutes > 0 | cSeconds > 0) {}
    ++ Choir;
    ++ cMinutes;
    fH = chorus - Thur;
    fM = cMinutes - tMinute;
    fS = cSeconds - tSecond.
    }
    else {}
    fH = chorus - Thur;
    fM = cMinutes - tMinute;
    fS = cSeconds - tSecond.
    }

    sH = fH + lastcallH;
    sM = fM + lastcallM;
    sS = fS + lastcallM;

    If (< 0 sH: sM < 0 | sS < 0)
    {
    sH = sH * (-1);
    sM = sM * (-1);
    sS = sS * (-1);
    }
    finalMil = (sH * 60) + (sM * 60) + (sM * 60);

    Allows you to implement a timer
    var yahooTime:Timer = new Timer (finalMil, repeat);
    var repeat: Number = 1;

    yahooTime.start ();

    yahooTime.addEventListener (TimerEvent.TIMER, displayCall);

    function displayCall(event:TimerEvent):void
    {
    trace ("well let's success");
    }

    your first trace() statement is almost certainly not what you want.

    dtDate2 is 08/08/2009

    and it's probably not what you want.  Flash months are zero-based.  That is to say, January corresponding to month 0 and December is the month 11.

  • calculate the time difference.

    Hello

    How to calculate the time difference by using javascript.

    Example 15.05 and18.35 difference is 2 h 30 min

    BTW: it isn't ~ 2h30min is 3h30min

    Maybe something like this works:

    // result is 3.300000000000002 ~ 3h 30min
    (parseFloat((18.35 - 15.05) / 3600) * 3600)
    
  • How do the time difference between two dates?

    Hi all

    I use this query to get the time difference between two dates.

    Select to_timestamp ('2012-10-03 12:00 ',' YYYY-MM-DD hh)-to_timestamp ('2012-10-03 11:00 ',' YYYY-MM-DD hh) as double diff;

    but do not get the correct result.

    Thank you

    Left KEY... Left Padding of tanks.

  • How to calculate the time difference

    Hi friends,

    I want to calculate and the sum of the time difference.

    I have two fields in a table. Inside and OUTSIDE. for example.

    OUT IN DIFFERENT

    01:46 15:30?

    01:47 15:45?

    02:50 17:30?

    I want less above figure and the result will appear in different column.

    Help, please

    Kind regards

    Hello

    Assuming that the two columns are the VARCHAR2 data type and "represent" the hours and minutes:

    WITH sample_data AS (SELECT ' 01:46 ' in_col, 15:30 ' out_col FROM DUAL)

    UNION ALL

    SELECT ' 01:47 ' 15:45 ' OF THE DOUBLE

    UNION ALL

    SELECT ' 02:50 ', 17:30 ' OF THE DOUBLE

    )

    SELECT in_col,

    out_col,

    TO_CHAR (TO_DATE ((TO_DATE(out_col, 'HH24:MI')-TO_DATE(in_col, 'HH24:MI')) * 86400, «SSSSS»), "HH24") differ))

    OF sample_data;

    SQL > WITH sample_data AS (SELECT ' 01:46 ' in_col, 15:30 ' out_col FROM DUAL)

    2. ANY TRADE UNION

    3. SELECT ' 01:47 ' 15:45 ' OF THE DOUBLE

    4 UNION ALL

    5. SELECT ' 02:50 ', 17:30 ' OF THE DOUBLE

    6                      )

    7. SELECT in_col,

    out_col 8,.

    9 to_char (TO_DATE ((TO_DATE(out_col, 'HH24:MI')-TO_DATE(in_col, 'HH24:MI')) * 86400, «SSSSS»), "HH24") differ))

    10 FROM sample_data;

    IN_COL OUT_COL DIFFER

    ------ ------- ------

    01:46 15:30 13:44

    01:47 15:45 13:58

    02:50 17:30 14:40

    SQL >

  • QML: calculate the time interval between the touch events

    I create a custom button that is activated by a key event, in this way:

    Container {
        property bool pressed
        signal clicked...
        onTouch: {
            if (enabled && ! event.isMove()) {
                if (event.isUp() && pressed) clicked()
                pressed = event.isDown()
            }
        }
    }
    

    The problem with this approach is that if the user clicks the custom button several times in a short period of time the click signal is triggered several times too. This does not happen if I use a regular button or an ImageButton.

    I was thinking about getting the timestamp of the event and fire the only if clicked event grit touch after at least x milliseconds since the previous event. The DIF is that I couldn't find a way to calculate this difference in QML.

    Any suggestions?

    You could also follow the time of the last event with the Javascript date.

    lastTouched = new Date().valueOf();
    

    -Check if time has passed...

  • How to set the time difference between each data when using keithley 2400 scanning

    Hello friends,

    I use scanning Keithley vi the extent of SCANNING and acquire vi. I want to measure the voltage for each step and a pause between each two data, so I need a delay between each I step.

    I'm a starter to use Labview, thank you very much for your answers.

    Perry

    As Dennis says, if you use the built-in scan function, you will need to consult the manual. See Section 10-16 (this is page 10 of article 16, only paragraphs not but 10, 16) for the manual Keithley 2400.

    The Keithley 24xx series has a speed of measurement in units called PLC (Power Line Cycles). The default speed is 1PLC, which means a measure is taken with each cycle of line 1 power supply or 1/60th of a second (16.67ms). 24XX can range from 0.01 PLC (all 0.16ms) 10 PLC (all 166.6ms). The faster you measure, the less accuracy you get.

    To programmatically set this value, the command is

    ENSe:CURRent:NPLCycles

    ENSe:VOLTage:NPLCycles

    Depending on what you are sensing and where is the number of controllers from 0.01 to 10.

    Another factor that will determine the time between data points is the cycle SDM. These are more complicated, look at your Keithley manual for more information. Look at article 6 and article 11 for more information.

    Note:

    PLC times are based on a cycle of 60 Hz US.

  • Measure the time difference between a digital output and an analog input that responded to the questionnaire

    Hallo,

    I use the following system:

    • OR PXI-1044 with controller NI PXI-8109

    • OR PXI-2564 switch module to turn on the monitor of my test device

    • Data acquisition multifunction NI PXI-6259 to measure the signal that responded to the questionnaire jump

    The two cards are the same - PXI trigger bus. For both, PXI-2564 and PXI-6259 I use DAQmx to set the reading and writing of the channels.

    Now, I want to measure the time between the digital output, my unit turns and the analog input, which measures the response of my system.

    I can't do work by myself, please help me!

    I thank Ludwig.

    Hi Ludwig,.

    If you can't give us any VI we have difficulties with to help you.

    Because I Donat knowledge how your program is mounted it is not easy to know where you should enter signals.

    Here's a question similar to yours:

    http://forums.NI.com/T5/LabVIEW/best-way-to-measure-time/TD-p/178704

    and 2 external links:

    http://www.ehow.com/how_8698983_measure-time-LabVIEW.html

    http://objectmix.com/LabVIEW/385152-how-can-i-use-LabVIEW-measure-time-between-analog-pulses.html

  • There is the time difference between I phone and Apple Watch

    Ythe time on my I phone is correct, but on my Apple Watch is not

    You have sync it and paired? in the same time zone?

  • How to calculate the time difference in the two date columns time.

    Hi Obiee Experts,

    I came back new requirement on obiee 10g.


    I have two date columns in my table time, data as below.

    StartDate: 18/03/2012-04:40:51

    Closing date: 18/03/2012-04:50:55

    I want to the output as below (Jet lag).

    output
    04:40:51 (less)-04:50:55 = 00:10:04

    I hope you understand my requirement in OBIEE.

    Note: I want to show above the output values in another State for OBIEE10g column.

    Please share me your valuable contributions. Urgent appeals.

    Thank you
    Satya

    Hi Satya,

    Here's another solution. You can try the formula below as it is:

    Cast (floor (TIMESTAMPDIFF (sql_tsi_second, '-SNP_SESSION '.))) SESS_BEG, '-SNP_SESSION '. SESS_END) / 3600) as char). ':' ||
    Cast (floor (mod (TIMESTAMPDIFF (sql_tsi_second, '-SNP_SESSION '.)))) SESS_BEG, '-SNP_SESSION '. ((SESS_END), 3600) / 60) as char). ':' ||
    Cast (mod (TIMESTAMPDIFF (sql_tsi_second, '-SNP_SESSION '.))) SESS_BEG, '-SNP_SESSION '. SESS_END), 60) as char)

    I would like to know if that's what you're looking for.

    Thank you

  • Calculate the time (time zones)

    Hello

    I'm trying to calculate the time (hours and minutes) needs to travel between point a and point b in terms of the time difference between the time zones.

    IE: A flight leaves New York at 17:00 and arrives in Frankfurt the next at 07:00

    Thanks for your help!

    SELECT TZ_OFFSET('America/New_York') new_york, TZ_OFFSET('Europe/Berlin') Frankfurt,

    TO_TIMESTAMP_TZ ('20140818170000-04:00 ','yyyymmddhh24misstzh:tzm ') flight_start,

    TO_TIMESTAMP_TZ ('20140819070000 + 02:00 ','yyyymmddhh24misstzh:tzm ') flight_end,

    TO_TIMESTAMP_TZ ('20140819070000 + 02:00 ','yyyymmddhh24misstzh:tzm ') - to_timestamp_tz ('20140818170000-04:00 ','yyyymmddhh24misstzh:tzm ') flight_duration

    OF THE DOUBLE

    NEW_YORK FRANKFURT FLIGHT_START FLIGHT_END FLIGHT_DURATION
    -04:00 + 02:00 18 AUGUST 14 05.00.00.000000000 PM - 04:00 AUGUST 19, 14 07.00.00.000000000 + 02:00 AM + 08:00:00.000000000 000000000

    Concerning

    Etbin

  • "There is a time difference between the client and the server"

    Unit 4.0.3

    Everything worked very well, and all of a sudden, I'm not able to connect to the server unit using any domain account. When I enter the domain/name username/password, I get this error message:

    ************************************************

    The system is unable to log on due to the following error:

    There is a time difference between the client and the server.

    Try again or contact your system administrator.

    **************************************************

    I can use the same domain account (unityinstall) and the journal in other machines. I can connect the machine to the unit using a local account. There is no time difference between the DC server and unity.

    Need help,

    Thank you

    Partha

    Log on to your LOCAL computer using an account that has privileges

    At the command prompt, type the following:

    NET TIME ancien_mot_passe/set

    Found this on the MS site:

    Cannot open a session if the Date and time are not synchronized

    http://support.Microsoft.com/default.aspx?scid=kb;en-us;232386&product=Win2000

  • query to calculate the value and produce new lines

    QUARTER CUSTOMER PRODUCT RETAIL_SALES_AMT WHOLESALE_AMT

    01/01/2006 ABC VACUUM CLEANER 454234,00 65633456.00
    01/04/2006 ABC VACUUM CLEANER 324562,00 45333234.00
    01/07/2006 ABC VACUUM CLEANER 67845423.00 NULL
    01/10/2006 ABC VACUUM CLEANER 67453453.00 NULL
    01/01/2007 ABC VACUUM CLEANER 56754633.00 NULL
    01/04/2007 ABC VACUUM CLEANER 45423434.00 NULL


    Hi guys,.

    It's a situation where I have to produce a few new lines with projections based on Q4 RETAIL_SALES_AMT
    RETAIL_SALES_AMOUNT and fourth ' rs following WHOLESALE_AMT. As you can see from the sample data for a specific customer,
    product I have populated only until 01/04/2006 retail_sales_amt but WHOLE_SALE amt for the same product and customer
    are there up to 01/04/2007.

    I have to produce a PROJECTED RETAIL_SALES_AMT and it must be inserted in a new line with an indicator to identify
    a proposed line. Here, in this case I have to produce a new line of projection from 07/01/2006,10/01/2006 and 01/01/2007
    the RETAIL_SALES_AMT. The method of calculation is provided for in:

    retail_sales_amt scheduled for 07/01/2006=.345+ ((01/07/2006 whole_sales-01/04/2006 whole_sales) / (01/04/2006 whole_sale)))
    * 01/04/2006 RETAIL_SALES_AMT and move forward to subsequent quarters.

    Is it possible that I can use a query to produce these new lines by calculating the RETAIL_SALES_AMT on the fly, or any other
    How to procedure.

    Please help as it seems a little complicated.

    Concerning

    Published by: user626688 on October 27, 2009 11:26

    Published by: user626688 on October 27, 2009 11:26

    Published by: user626688 on October 27, 2009 11:27

    Published by: user626688 on October 27, 2009 11:28

    Published by: user626688 on October 27, 2009 11:31

    Published by: user626688 on October 27, 2009 11:32

    Hello

    As far as I can tell, that's what you asked for:

    WITH     got_prev         AS
    (
         SELECT     table_x.*
         ,     LAG (wholesale_amt) OVER ( PARTITION BY  customer
                                        ,                product
                                ORDER BY      quarter
                               )     AS prev_wholesale_amt
         FROM     table_x
    --     WHERE     ...     -- Any filtering goes here
    )
    ,     tree     AS
    (
         SELECT     got_prev.*
         ,     SYS_CONNECT_BY_PATH ( CASE
                               WHEN  LEVEL = 1
                               THEN  retail_sales_amt
                               ELSE  ( .345
                                              + wholesale_amt
                                              - prev_wholesale_amt
                                  ) / prev_wholesale_amt
                              END
                            , '*'
                            )                    AS path
         FROM     got_prev
         START WITH     retail_sales_amt     IS NOT NULL
         CONNECT BY     retail_sales_amt     IS NULL
              AND     quarter               = ADD_MONTHS (PRIOR quarter, 3)
              AND     customer          = PRIOR customer
              AND     product               = PRIOR product
    )
    SELECT       quarter
    ,       customer
    ,       product
    ,       COALESCE ( retail_sales_amt
                 , eval_number ( LTRIM ( path
                                           , '*'
                               )       )
                 )      AS retail_sales_amt
    ,       wholesale_amt
    ,       NVL2 ( retail_sales_amt
                , 'F'
                , 'T'
                )          AS projected_flag
    FROM       tree
    ORDER BY  customer
    ,            product
    ,       quarter
    ;
    

    I posted earlier the eval_number function.

    In this query, a group of consecutive quarters, where the first group a retail_sales_num and the rest of the members of the group are not, is treated as a hierarchy. The retail_sales_amt of all members (except the first) will be based on the previous, as well as the wholesale_amts past and present.
    Say that a tree is 5 points of time (as in your examples of data). We can calculate the 2nd point in several ways: using analytical functions, for example. But we cannot use the same formula to calculate the 3rd point, because the calculation of section 2 must be completed before we can calculate the 3rd. It goes the same for the 4th and 5th.
    This is CONNECT BY arrives. CONNECT BY is one thing in Oracle SQL that can be recursively; children may find themselves once their parents are found, in the same way we want to calculate the nth retail_sales_amt once the amount of the n-minus-1 has been calculated. To do this, we use SYS_CONNECT_BY_PATH, where the first element in the path is the retail_sales_amt given, and all others are the factor to multiply this number to get the next amount.
    SYS_CONNECT_BY_PATH produces a string like ' * 324562 *. 4965935 *-. 0057739', which should be interpreted as a number. TO_NUMBER won't: TO_NUMBER cannot convert only a single numeric literal. Instead, we have a function defined by the user who put this string dynamically in the SELECT clause of a query, where it is interpreted as a numeric expression.

  • What is the main difference between Excel Addin and SmartView?

    Hi all
    What is the difference between Excel Addin and SmartView in Hyperion 11.1.2?

    Thanks in advance

    RSG

    Published by: RSG on March 29, 2011 05:42

    If you want the main difference between the Excel add-in and smartview I'd say it's just they way it connects and retrieves the data. the add-in uses the grid api and tcpip and smartview uses java on the web. There are a ton of differences between the supplement and smartview, but as the versions come thay are close. Here are a few others can add to the list:

    ---------------------------------------------------------------------Add-in------------------------------smartview
    works on several office products - no - yes
    Can connect to
    Essbase-----------------------------------------------------------No---------------------------------------Yes
    HFM----------------------------------------------------------------No---------------------------------------Yes
    Planning----------------------------------------------------------No---------------------------------------Yes
    Can view members and aliases at once - Yes - No
    Leaf specific options - Yes - No
    Great shims formatting - Yes - sometimes

Maybe you are looking for