Calculate difference from last hour ?

hello all,
I have a sql query like below...
SELECT sn.snap_time, st.value
FROM PERFSTAT.STATS$SYSSTAT st, PERFSTAT.STATS$SNAPSHOT sn
WHERE st.snap_id = sn.snap_id
and st.NAME = 'user calls'
and sn.snap_time > to_date('03/01/2011 10:00:00', 'mm/dd/yyyy hh24:ss:mi')
order by 1 desc
and output is below....
SNAP_TIME VALUE
19-DEC-11 08:0:00 123501120
19-DEC-11 07:0:00 121336929
19-DEC-11 06:0:01 119910473
19-DEC-11 05:0:01 118900726
19-DEC-11 04:0:07 118244503
19-DEC-11 03:0:01 117202971
19-DEC-11 02:0:01 115791474
19-DEC-11 01:0:03 114008304
19-DEC-11 00:0:02 111347506
18-DEC-11 23:0:01 108291559
18-DEC-11 22:0:02 104340139
18-DEC-11 21:0:01 99255636
18-DEC-11 20:0:02 92775319
18-DEC-11 19:0:01 85262323
18-DEC-11 18:0:01 76262794
18-DEC-11 17:0:01 68381704
18-DEC-11 16:0:01 60100822
18-DEC-11 15:0:01 51855773
18-DEC-11 14:0:01 43733973
18-DEC-11 13:0:01 35903397
18-DEC-11 12:0:01 28494465
18-DEC-11 11:0:01 21724443
18-DEC-11 10:0:02 15667617
18-DEC-11 09:0:01 10526163
18-DEC-11 08:0:01 6741565
18-DEC-11 07:0:00 3622640
18-DEC-11 06:0:01 1623214
18-DEC-11 05:0:03 207054
but how can i write my query in a way so i can get the actual value/difference from the hour before
....all the above value is cumulative and i want to calculate the value from actual time...lets say starting
18-DEC-11 05:0:03 ...
hope it make sense...i am on 9.2.0.5

Hi,
To show the difference from the previous row (where "previous" is based on snap_time, ASCendcing order):
SELECT    sn.snap_time
,        st.value
,       st.value - LAG (st.value) OVER (ORDER BY snap_time)     AS value_change
FROM        PERFSTAT.STATS$SYSSTAT     st
,        PERFSTAT.STATS$SNAPSHOT     sn
WHERE        st.snap_id     = sn.snap_id
AND       st.NAME     = 'user calls'
AND       sn.snap_time     > TO_DATE ( '03/01/2011 10:00:00'
                          , 'mm/dd/yyyy hh24:ss:mi'
ORDER BY  snap_time     DESC
;In yopur sample data, it looks like every row is about a hour away from its neighbors. If you missed an hour, or if you sometimes had two (or more) rows in the same hour, then what results wouold you want? Post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables, and also post the results you want from that data.

Similar Messages

  • How do you calculate difference in time (hours and minutes) between 2 two date/time fields?

    Have trouble creating formula using FormCalc that will calculate difference in time (hours and minutes) from a Start Date/Time field and End Date/Time field. 
    I am using to automatically calculate total time in hours and minutes only of an equipment outage based on a user entered start date and time and end date and time. 
    For example a user enters start date/time of an equipment outage as 14-Oct-12 08:12 AM and then enters an end date/time of the outage of 15-Oct-12 01:48 PM.  I need a return that automatically calculates total time in hours and minutes of the equipment outage.
    Thanks Chris

    Hi,
    In JavaScript you could do something like;
    var DateTimeRegex = /(\d\d\d\d)-(\d\d)-(\d\d)T(\d\d):(\d\d)/;
    var d1 = DateTimeRegex.exec(DateTimeField1.rawValue);
    if (d1 !== null)
        var fromDate = new Date(d1[1], d1[2]-1, d1[3], d1[4], d1[5]);
    var d2 = DateTimeRegex.exec(DateTimeField2.rawValue);
    if (d2 !== null)
        var toDate = new Date(d2[1], d2[2]-1, d2[3], d2[4], d2[5]);
    const millisecondsPerMinute = 1000 * 60;
    const millisecondsPerHour = millisecondsPerMinute * 60;
    const millisecondsPerDay = millisecondsPerHour * 24;
    var interval = toDate.getTime() - fromDate.getTime();
    var days = Math.floor(interval / millisecondsPerDay );
    interval = interval - (days * millisecondsPerDay );
    var hours = Math.floor(interval / millisecondsPerHour );
    interval = interval - (hours * millisecondsPerHour );
    var minutes = Math.floor(interval / millisecondsPerMinute );
    console.println(days + " days, " + hours + " hours, " + minutes + " minutes");
    This assumes that the values in DateTimeField1 and DateTimeField2 are valid, which means the rawValue will be in a format like 2009-03-15T18:15
    Regards
    Bruce

  • SQL Query find month/year and then calculate difference from start date

    Hi All,
    Assume I have a table with a column Start_Date. I like to know how we can build a query to so we can find the end of the month date based on the start_ date and then calculate the difference
    For example lets say we have a date 12/06/2014 and now based on this we should get the end of the month date which is 30/06/2014. Now we can get the difference which is 18 days.
    Thanks

    Hi Jaggy99,
    According to your description, you need to get the date difference between a given date and the last day of that month, right?
    In this case, please try the query below.
    SELECT GETDATE() AS [CURRENTDAY], DATEADD(DAY,-1,DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) + 1, 0)) AS [LASTDAY],
    DATEDIFF(DAY, GETDATE (), DATEADD(DAY,-1,DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) + 1, 0))) AS [DIFFERENCE]
    Regards,
    Charlie Liao
    TechNet Community Support

  • How to calculate difference between date in hours?

    Hi All.
    I need calculate difference between first and last date. I'm using the code below:
    int differenceDate = CalendarRule.elapsedDays(fromDate : myFirstDate, toDate : myLastDate);
    This code return an result in days. But I need that result was in hours.
    Has anybody help me?

    Interval dif;
    dif = myLastDate - myfirstDate;
    display((dif.hours));
    Hope it helps

  • Difference  Between Provide and RP-PROVIDE-FROM-LAST  in ABAP-HR

    what is the Difference Between Provide and RP-PROVIDE-FROM-LAST  IN hR. IF I want to retrieve data in BETTWEEN BEGDA AND ENDDA. what these 2 ill return.
       Both ill return the LAtest record. plz  let me know what ill happen.
      With Regards,
       Venkata Suresh K

    PROVIDE is like a loop statement and it reads records between BEGDA and ENDDA. There is a lot to it, you can read doc...
    RP-PROVIDE-.. _> This is like read table.
    It is similar to : Sort itab descending. read itab index 1.
    If you want data between BEGDA and ENDDA and you have 2 internal tables, you can use PROVIDE. Otherwise, you can use a normal LOOP statement. Provide is helpful if you want to get data from more than 1 table.
    For eg: Infotype 0000 has 2 records from 1.1.2000 to 1.1.2006, and 2.1.2006 to 31.12.9999, and Infotype 0185 has 1 record from 1.1.2005 to 31.12.9999.
    If you use a provide BETWEEN BEGDA and endda in this case, it will run through the loop 3 times with these dates :
    1.1.2000 to 31.12.2004.
    1.1.2005 to 1.1.2006
    2.1.2006 to 31.12.9999
    If a record is not there in one of the internal tables during the date, there is a PNNNN_VALID flag which is filled up (4.6c) and in mySAP onwards, you have explicit valid flags.
    Hope it helps. Please reward points if helpful.
    Regards.
    Samant

  • Difference between RP_PROVIDE_FROM_LAST and RP-PROVIDE-FROM-LAST

    Can anyone tell me the difference between RP_PROVIDE_FROM_LAST and RP-PROVIDE-FROM-LAST?  Both the macros are same difference is with underscore(_) and hiphen(-).  Both are working fine for the functionality without any difference.  Then why there are two macros for a single functionality?

    Just providing the links are considered as link farming ( which are against the rules of the forums ), the links would be removed for the following reasons:
    1) If a link is provided( not many ) , then you must point out the explanation in it
    2) If the links were easily searchable by the OP
    3) If the links just direct you to sap documentation
    4) If the reply consists only bunch of link references.
    I think the 3rd & 4th point made your post to be deleted.
    There are no links which states the differences between these two Macro's. Mod's are doing their right job, please join them and make this forum clean
    Kesav

  • When I locate my iPad it sends me my email but the time it says in the email is like a 3 hour difference from the actual time I locate what do I do to have the proper time there

    When I locate my iPad it sends me my email but the time it says in the email is like a 3 hour difference from the actual time I locate what do I do to have the proper time there
    My time is correct but email time of location is wrong

    Welcome to the Apple community TMOZINGO.
    If you are unable to remember your password, security questions, don’t have access to your rescue address or are unable to reset your password for whatever reason, your only option is to contact AppleCare(or Apple ID Support), upon speaking to an operator you should explain that your problem is related to your Apple ID, this way you will not be charged for assistance, even if you don’t have an AppleCare plan.
    The operator will take you through some steps you may have already tried, however they need to be sure they have exhausted all usual approaches before trying to reset your account, so you should try to be helpful and show patience with the procedure.
    The operator will need to verify they are speaking to the account holder and may ask you some questions that only the account holder could know, and you will need to answer them if the process is to proceed.
    Once the operator has verified your identity they will send a message through to your device which contains an alpha numeric code, which you will need to read back to them.
    Once this has been completed they will send an email to your iCloud email address after a period of 24 hours, so you should check that mail is enabled in your devices iCloud settings.
    Upon receipt of the email, use the reset link provided to reset your password, after which you should be able to make the adjustments to iCloud that you wish to do.

  • 421 4.4.5 Too many messages from this host last hour

    Hi, we are in a migration process from a Kerio system to Exchange 2013.
    Everything is working fine, except that we have been experiencing this error on the logs and the Exchange 2013 users are getting returned emails.
    The remote server is 10.10.10.85
    Remote Server at 10.10.10.85 (10.10.10.85) returned '400 4.4.7 Message delayed'
    19/12/13 7:21:57 p. m. - Remote Server at 10.10.10.85 (10.10.10.85) returned '451 4.4.0 Primary target IP address responded with: "421 4.4.5 Too many messages from this host last hour." Attempted failover to alternate host, but that did not succeed.
    Either there are no alternate hosts, or delivery failed to all alternate hosts. The last endpoint attempted was 10.10.10.85:25'
    My question is, is Exchange rejecting the messages or is the other system telling Exchange to slow things a bit?

    To update this.
    We found out that the other email system was configured NOT to accept more than 100 messages per hour from same sending IP.
    Once we removed the configuration value from the other email system, all started working.

  • I was erase all contect and data after it it showing only apple  logo from last 2 hour i need help

    i was erase all contect and data after it it showing only apple  logo from last 2 hour i need help

    You should reset your iPhone,
    Reset your iPhone by pressing the 'Sleep' and 'Home' button at the same time for about 15 seconds or so. Your iPhone will then go through a reset / reboot procedure and will be ready for use within about a minute.
    Don't worry about doing this as you will not lose data or settings.
    Good luck and do report back.

  • What is difference between rp-provide-from-last VS rp_provide_all

    Hello All:
        I have the following code:
    rp-provide-from-last p0000 space pn-begda pn-endda. -- I know this statement gets latest record from Infotype 0 for the given period.
    rp_provide_all       p0210 'FED' pn-begda pn-endda.
    Could someone please tell me what exactly the code above does? Rewards assured.
    Thanks.
    Mithun

    RP_PROVIDE_ALL does not look like a standard macro. I have checked entries in TRMAC table and it does not return anything for this macro name.
    I believe there must be custom macro created in your program which is used here. Please check the program and see if the declaration is available for RP_PROVIDE_ALL.
    ashish

  • Averaging over the last hour and last eight hours.

    This is fairly simple but I'm not sure what a "good" approach is. Basically I need to track how many times a user has performed an action over the last hour and last eight hours. I'll receive a notification of some sort when they perform this action and could get the current time, but I'm not sure what a fast way of determining how many times this has occurred in a given time period is.
    I was thinking perhaps an array with the time of each in milliseconds and just find the first index that was < 8 hours or < 1 hour ago and then subtract the index from the current size. I think that would be problematic though. To keep the array from continuously growing I'd have to shift everything over to the left which means an expensive arraycopy. Perhaps if I only did the resizing when there were > 20 or elements I no longer care about or something would help, but then I'd have to iterate over 20 elements I don't care about everytime it's calculated, which is once a second.
    Any algorithms that will solve this?

    Here is a method with a granularity of a minute (i.e.
    it only updates the average value every minute - you
    can change it to give whatever granularity you want)
    Keep an array with 60 elements in it. The array
    counts the number of times that the user performed
    the action each minute.
    The array in indexed modulo real time, and you make
    entries based on actual time of day. So when a user
    performs an action at 8:38:45 you increment slot 38.
    Each slot counts the number of actions that took
    place in that particular minute. When the next minute
    rolls around, you move to the next slot, set the
    value to zero (thus throwing out the events that
    happened over an hour ago, and prepare to count the
    new events)
    The sum of the entire array is of course the total
    number of events that have taken place in the last
    hour.
    You do not need to actually run through the array and
    total the events every time you want to calculate the
    average. You can use the fact that you increase the
    total by one every time you get a new event and you
    decrease the total by X everytime you zero out a slot
    that had X for its event count.
    So you can just keep a single value, Total, along
    with your array that goes up by one on every event
    and then drops back a little every minute, when you
    throw out the hour old events.That is probably a good solution to the question I posed, but I realize now I was not thorough or accurate enough in describing the context and requirements. I don't think that will work without a lot of unnecessary memory, but maybe I'm wrong.
    The user action is actually the successful completion of entering a form, a bill to be more precise. I expect this to happen 100-300 times an hour to give an idea of the frequency. Given a period of time, if they've been at it for that period of time or longer I need to find the number of bills completed in that most recent period of time. Otherwise, I need to use what is available to predict what they will reach in that period of time. In other words, if the time period is an hour I need to figure out how many bills were completed in the last hour, but if they've been going for only five minutes I need to predict what they will have completed in an hour including those last five minutes. Then I need to do the same thing for seven hours, using the last seven hours or less of data.
    I guess I'd just have to use a granularity of a minute or less and calculate how many bills over how many minutes and make a prediction on that? I suppose I was hoping for something more precise, but now that I think about it that will probably suffice.
    How would you implement it though? Create a "minute" array of size 60 initially, then when reaching the end of that array adding the total for that array to an "hourly" array (keeps track of bills in that hour) and then start over? I guess then you'd just have to add each from the hourly array to the current total and calculate based upon that. At any given time I'd have the number of bills processed in the last x hours and y minutes, which is enough to calculate how much can be completed at that rate in a given hour or seven hour day.
    I'll try this tomorrow when I get to work, thank you very much I was needlessly complicating it with timestamps. In fact, this inadvertently (or perhaps purposefully?) solves an issue with not calculating time when a user is at lunch or on break. At least I think it does.

  • Need Help to calculate difference between times

    Hello everyone,
    I have two fields which just stores the time in 24 hour format ex: 08:00 and 20:00 now I want to calculate difference between the two times
    Kindle help me
    Thanks for your help
    Thanks
    Ravi

    Are your fields of varchar2 datatype or...?
    Is 08:00 the start time or 20:00?
    Date arithmetic is pretty simple in Oracle if you use the right datatype.
    See:
    http://asktom.oracle.com/pls/asktom/ASKTOM.download_file?p_file=6551242712657900129
    Assuming you are storing strings:
    SQL> -- generating sample data:
    SQL> with t as (
      2  select '08:00' btime, '20:00' etime from dual
      3  )
      4  --
      5  -- actual query:
      6  --
      7  select numtodsinterval(to_date(etime, 'hh24:mi') - to_date(btime, 'hh24:mi'), 'day') nti
      8  ,      (to_date(etime, 'hh24:mi') - to_date(btime, 'hh24:mi'))*24 dt
      9  from   t;
    NTI                                                                                 DT
    +000000000 12:00:00.000000000                                                       12
    1 row selected.
    SQL>

  • Data not coming to BW from SAP system from last 7 days....please help

    Hi Experts,
    I am monitoring the process chain from last 7-8 days but no data is coming to BW from SAP R/3 . then i checked in SAP R/3 system in RSA7 there weree no queues it was empty. then i checked LBWQ and some MCEX03,MCEX11,MCEX13,MCEX04 were there and i double clicked on one of them then i saw the status in queue as NOSEND . we have used QUEUED DELTA as update mode in LBWE. now i want to bring data for last 7-8 days in BW system. please can anyone provide me the detail steps for this as it is our PRODUCTION system. please provide the steps...!!!!

    Hi,
    Go to SM37 in your R/3 environment and check if there are any jobs starting with LIS* in released status. This is the job which would push the entries from LBWQ to RSA7 for specific applications. If there are no jobs, this is the reason for your problem.
    If you do find any job there, then double click on them to check their frequency. Generally it should be hourly.
    If there is no such job, then go to LBWE. For each of your applications, click on Job Control and maintain the job scheduling. In the start date, maintain it as periodic job. Then simply schedule teh jobs. Once the jobs are scheduled, after every run of them, LBWQ would get cleared.
    Then it would get picked from RSA7 by the BI job.
    Edited by: Rahul K Rai on Dec 8, 2010 4:00 PM

  • Within the last hour, I noticed that my older MacBook Pro, while I was playing it in iTunes, lost contrast on the screen.  I am sorry, but I did not take exact notes on this event.  Around the same time, I did do a back up, uploaded software, etc.

    Within the last hour, I noticed that my older MacBook Pro, while I was using iTunes, lost contrast on the screen.  I am sorry, but I did not take exact notes on this event.  Around the same time, I did do a back up, uploaded Apple software, etc.
    I'm using two MacPros simultaniously, the old one for iTunes, and the new one for the other things.  My new one has no problems, so am wondering if there is an easy way to correct the older MacPro's contrast problems.  The computer is over three years old, and I'm wondering also if this failure is an aging sign.  (I also have other problems, such as a noisy DVD drive, which is part of the reason I bought a new MacBook Pro.)

    Is the older MBP a pre-Unibody model from early 2008? If so, it could be having this problem:
    http://support.apple.com/kb/ts2377
    If so, you would be entitled to a free repair.
    The lost contrast could be considered distorted video.
    Do you have an external monitor? If the external shows the same lost contrast, the graphics chip is likely the culprit. If the external is OK, then you probably have an issue with the built in display or possibly with its connections.
    You may also want to check in Universal Access to see if the contrast bar is set in its normal position (all the way to the left).
    Apple has a special test they can run to diagnose the NVIDIA issue, so if you have access to an Apple Store, make an appointment at the genius bar to have it run.
    Good luck!

  • I just tried to reset factory settings on my i phone 4 s it still downloading from 5 hours

    i just tried to reset factory settings on my i phone 4 s it still downloading from 5 hours..i dont know what to do

    I didn't think of this earlier, but if it makes any difference: the PC I'm running iTunes on and have had this iPhone connected to is running Windows 7 Ultimate.

Maybe you are looking for