Average for periods of 3 hours

Hi all

I am trying to create a query that will return a week at a given time and check and see if there are periods of 3 hours where avg exceeds a given value. I will be passing the date and the threshold of an app so no need to worry there. The question, I am stuck on is how iterate over each period of 3 hours and take the average of the values in the meantime? For example, taking the sample data below... the iteration of fir trees would start one up and go until 03:00 and the result would be: CCA | 2011-08-06 00:00:00 | 0.522133333 and the next CCA | 2011-08-06 00:03:00 | 0.530833333 etc.

EXAMPLE of FIRST 3 hours
0.5169
0.5117
0.5117
0.5274
0.5482
0.5169
AVG
0.522133333

SAMPLE OF ALL DATA

Value of the Date element
CCA 2011-08-06 00:00:00.5169
CCA 2011-08-06 00:30:00.5117
CCA 2011-08-06 01:00.5117
CCA 2011-08-06 01:30.5274
CCA 2011-08-06 02:00.5482
CCA 2011-08-06 02:30.5169
CCA 2011-08-06 03:00.5117
CCA 2011-08-06 03:30.5482
CCA 2011-08-06 04:00.5169
CCA 2011-08-06 04:30.5065
CCA 2011-08-06 05:00.5169
CCA 2011-08-06 05:30.5848
CCA 2011-08-06 06:00.5065
CCA 2011-08-06 06:30.5013
CCA 2011-08-06 07:00.5221
CCA 2011-08-06 07:30.5587
CCA 2011-08-06 08:00.543
CCA 2011-08-06 08:30.5117
CCA 2011-08-06 09:00.5169
CCA 2011-08-06 09:30.5274
CCA 2011-08-06 10:00.7519
CCA 2011-08-06 10:30.9294
CCA 2011-08-06 11:00.9399
CCA 2011-08-08 12:00.5117
CCA 2011-08-08 12:30.5169
CCA 2011-08-08 13:00.5274
CCA 2011-08-08 13:30.637
CCA 2011-08-08 14:00.6788
CCA 2011-08-08 14:30.637
CCA 2011-08-08 15:00.6527
CCA 2011-08-08 15:30.684
with sample_data as (
                     select 'cca' item,to_date('2011-08-06 00:00:00','yyyy-mm-dd hh24:mi:ss') dt,.5169 val from dual union all
                     select 'cca',to_date('2011-08-06 00:30:00','yyyy-mm-dd hh24:mi:ss'),.5117 from dual union all
                     select 'cca',to_date('2011-08-06 01:00:00','yyyy-mm-dd hh24:mi:ss'),.5117 from dual union all
                     select 'cca',to_date('2011-08-06 01:30:00','yyyy-mm-dd hh24:mi:ss'),.5274 from dual union all
                     select 'cca',to_date('2011-08-06 02:00:00','yyyy-mm-dd hh24:mi:ss'),.5482 from dual union all
                     select 'cca',to_date('2011-08-06 02:30:00','yyyy-mm-dd hh24:mi:ss'),.5169 from dual union all
                     select 'cca',to_date('2011-08-06 03:00:00','yyyy-mm-dd hh24:mi:ss'),.5117 from dual union all
                     select 'cca',to_date('2011-08-06 03:30:00','yyyy-mm-dd hh24:mi:ss'),.5482 from dual union all
                     select 'cca',to_date('2011-08-06 04:00:00','yyyy-mm-dd hh24:mi:ss'),.5169 from dual union all
                     select 'cca',to_date('2011-08-06 04:30:00','yyyy-mm-dd hh24:mi:ss'),.5065 from dual union all
                     select 'cca',to_date('2011-08-06 05:00:00','yyyy-mm-dd hh24:mi:ss'),.5169 from dual union all
                     select 'cca',to_date('2011-08-06 05:30:00','yyyy-mm-dd hh24:mi:ss'),.5848 from dual union all
                     select 'cca',to_date('2011-08-06 06:00:00','yyyy-mm-dd hh24:mi:ss'),.5065 from dual union all
                     select 'cca',to_date('2011-08-06 06:30:00','yyyy-mm-dd hh24:mi:ss'),.5013 from dual union all
                     select 'cca',to_date('2011-08-06 07:00:00','yyyy-mm-dd hh24:mi:ss'),.5221 from dual union all
                     select 'cca',to_date('2011-08-06 07:30:00','yyyy-mm-dd hh24:mi:ss'),.5587 from dual union all
                     select 'cca',to_date('2011-08-06 08:00:00','yyyy-mm-dd hh24:mi:ss'),.543 from dual union all
                     select 'cca',to_date('2011-08-06 08:30:00','yyyy-mm-dd hh24:mi:ss'),.5117 from dual union all
                     select 'cca',to_date('2011-08-06 09:00:00','yyyy-mm-dd hh24:mi:ss'),.5169 from dual union all
                     select 'cca',to_date('2011-08-06 09:30:00','yyyy-mm-dd hh24:mi:ss'),.5274 from dual union all
                     select 'cca',to_date('2011-08-06 10:00:00','yyyy-mm-dd hh24:mi:ss'),.7519 from dual union all
                     select 'cca',to_date('2011-08-06 10:30:00','yyyy-mm-dd hh24:mi:ss'),.9294 from dual union all
                     select 'cca',to_date('2011-08-06 11:00:00','yyyy-mm-dd hh24:mi:ss'),.9399 from dual union all
                     select 'cca',to_date('2011-08-08 12:00:00','yyyy-mm-dd hh24:mi:ss'),.5117 from dual union all
                     select 'cca',to_date('2011-08-08 12:30:00','yyyy-mm-dd hh24:mi:ss'),.5169 from dual union all
                     select 'cca',to_date('2011-08-08 13:00:00','yyyy-mm-dd hh24:mi:ss'),.5274 from dual union all
                     select 'cca',to_date('2011-08-08 13:30:00','yyyy-mm-dd hh24:mi:ss'),.637 from dual union all
                     select 'cca',to_date('2011-08-08 14:00:00','yyyy-mm-dd hh24:mi:ss'),.6788 from dual union all
                     select 'cca',to_date('2011-08-08 14:30:00','yyyy-mm-dd hh24:mi:ss'),.637 from dual union all
                     select 'cca',to_date('2011-08-08 15:00:00','yyyy-mm-dd hh24:mi:ss'),.6527 from dual union all
                     select 'cca',to_date('2011-08-08 15:30:00','yyyy-mm-dd hh24:mi:ss'),.684  from dual
                    )
select  item,
        trunc(dt) + trunc((dt - trunc(dt)) * 24 / 3) / 8 dt,
        avg(val) val
  from  sample_data
  group by item,
           trunc(dt) + trunc((dt - trunc(dt)) * 24 / 3) / 8
  order by item,
           trunc(dt) + trunc((dt - trunc(dt)) * 24 / 3) / 8
/

ITE DT                         VAL
--- ------------------- ----------
cca 2011-08-06 00:00:00 .522133333
cca 2011-08-06 03:00:00 .530833333
cca 2011-08-06 06:00:00 .523883333
cca 2011-08-06 09:00:00      .7331
cca 2011-08-08 12:00:00      .5848
cca 2011-08-08 15:00:00     .66835

6 rows selected.

SQL> 

SY.

Tags: Database

Similar Questions

  • Up to version 7.01 FF ever hanged, but with 7.01, after having not used for a period of time (hours or less), it crashes. No solution except again?

    Up to version 7.0.1 but never crushed/hnag, FF with 7.0.1 after you have not used for a period of time (hours or less), it crashes. No solution except again?

    Upgrade your browser Firefox 8 and try

  • How to calculate daily, hourly average for the very large data set?

    Some_Timestamp

    "Parameter1" Parameter2
    1 JANUARY 2015 02:00. 00:000000 AM - 07:002341.4534676341.4534
    1 JANUARY 2015 02:00. 01:000000 AM - 07:002341.4533676341.3
    1 JANUARY 2015 03:04. 01:000000 PM - 07:005332.3533676341.53
    1 JANUARY 2015 03:00. 01:000046 PM - 07:0023.3436434.4345
    JANUARY 2, 2015 05:06.01:000236 AM - 07:00352.3343543.4353
    JANUARY 2, 2015 09:00. 01:000026 AM - 07:00234.453453.54
    3 FEBRUARY 2015 10:00. 01:000026 PM - 07:003423.3534634.45
    FEBRUARY 4, 2015 11:08. 01:000026 AM - 07:00324.3532534534.53

    We have data as above a table and we want to calculate all the days, the hourly average for large data set (almost 100 million).  Is it possible to use the sql functions of analysis for better performance instead of the ordinary average and group of?  Or any other way better performance?

    Don't know if that works better, but instead of using to_char, you could use trunc. Try something like this:

    select
        trunc(some_timestamp,'DD'),
        avg(parameter1)
    from
       bigtable
    where
       some_timestamp between systimestamp-180 and systimestamp
    group by
       trunc(some_timestamp,'DD');
    

    Hope that helps,

    dhalek

  • my order is over a period of 24 hours, I want to cancel my order for now

    stopped the plan of the student over a period of 24 hours and I have not received my order. I'll like to cancel my order, how can I do?

    Return, cancel or change an Adobe order-

    http://helpx.Adobe.com/x-productkb/policy-pricing/return-cancel-or-change-order.html

    Cancel your subscription or membership. Creative cloud

    https://helpx.Adobe.com/x-productkb/policy-pricing/cancel-membership-subscription.html

  • Statistics calculation of schema for a huge 10 hours batch

    Hello

    We are on gR 11, 2 (11.2.0.4) Oracle Linux. The integrated schema statistics collection job is configured to run only during the night now in production.

    We have a huge batch moving a very large amount of data in almost 90% of the tables in the database (only get tables are not affected). It will take about 10 hours and is scheduled over the weekend. It's a big ETL process that moves a huge amount of data from a database (source) to another (target) database.  How can I go to ensure that schema statistics are updated when this heavy DML constantly occurs during this period of 10-hour day?  What is the best practice to adopt in such a scenario? What I read in the Oracle documentation, which is

    "For tables that are loaded in bulk, procedures for the collection of statistics must be run on these tables immediately after the loading process, preferably as part of the same script or job that executes the bulk loading.

    How to batch? One option is to "divide the lots say 5 equal pieces" and after that each piece is finished, run the stats together. What is the best way to do it?

    I will be grateful for the entries on it.

    Thank you

    OrauserN

    We have a huge batch moving a very large amount of data in almost 90% of the tables in the database (only get tables are not affected). It will take about 10 hours and is scheduled over the weekend. It's a big ETL process that moves a huge amount of data from a database (source) to another (target) database.

    OK - but this does not explain why you have a question about what stats should be executed. And you do not mention what system, the source or the target. your stats is everything.

    How can I go to ensure that schema statistics are updated when this heavy DML constantly occurs during this period of 10-hour day?  What is the best practice to adopt in such a scenario? What I read in the Oracle documentation, which is

    "For tables that are loaded in bulk, procedures for the collection of statistics must be run on these tables immediately after the loading process, preferably as part of the same script or job that executes the bulk loading.

    The recommendation is ONLY for the use case where there is a concomitant use of these ' tables that are loaded in bulk.

    Yet once, you did not mention ANY use of the data in the systems of your source or target. Without knowing how the data is used DURING THE MOVE, we can give advice:

    1. what 'pass' given average to you? You are "suppressing" the data from the source system and "insert" then the same data in the target system? Or you just ' data are copied "from source to the target?

    2 users perform DML on tables of source? If data comes to be SELECTED from those tables and not deleted, so you need not to run statistics on the source system.

    3. users perform DML on target tables? What is DML performed during loading the new data? Then the load might affect the performance of the executed DML.

    How to batch? One option is to "divide the lots say 5 equal pieces" and after that each piece is finished, run the stats together. What is the best way to do it?

    Who knows? You have not even told us:

    1. what system, source or target or both, you are talking about

    2. What does batch processing

    3. what DML is to be carried out at the same time as the treatment by lots

    Much depends on the type of DML performed and used tables and the structure of lots. It could be that a step-by-step process could be used. That would be a bit similar to what you proposed except that he wouldn't use the table stats, stats of schema:

    1. run the part of lot 1 which updates some tables that uses certain DML

    2. collect statistics table on the tables affected by part 1 - which minimizes the effect of 'statistics' in this part of the load

    3. run the part of lot 2 that updates some different tables that affect different DML

    4 collect statistics table on the tables affected by part 2

    5 and so on

  • Introduction to iCloud but "glued" for more than 12 hours

    I am new to icloud and try to put up my pictures in icloud.

    in the Photos on my imac, he says it's "uploading 11 983 points", but he's been stuck like that for more than 12 hours.

    If I click on icloud in system preferences, it is also stuck and will not let me click on anything whatsoever.

    What should I do now?

    The first part in the photos is not uncommon, the initial download may take days and seems to stall for long periods of time. The second part on the system preferences is unusual, have you tried to restart the Mac yet.

  • Get performance statistics of a VM method for the last 2 hours

    Need a scipt for toolkit VI to obtain performance statistics of a VM method for the last 2 hours

    What metrics (cpu.usage.average, disk.usage.average...) are you looking for?

    Have you tried one of the preconfigured metric collections (Cpu, memory, disk, network) which are available in the cmdlet Get-Stat?

    An example with the scope of the Cpu

    get-vm  | Get-Stat -Cpu -Start (Get-Date).addhours(-2) -IntervalMins 2 -MaxSamples 60
    
  • I tried to erase and reset my iphone 6 s. But why is it taking so long? For more than 24 hours. Is this normal? The phone displays just the apple logo and wont open. Help, please. Thank you in advance.

    I tried to erase and reset my iphone 6 s. But why is it taking so long? For more than 24 hours. Is this normal? The phone displays just the apple logo and wont open. Help, please. Thank you in advance.

    Hello

    Follow the instructions here:

    If you are unable to update or restore your iPhone, iPad or iPod touch - Apple supports

  • 10.11.5 was their stall for more than 2 hours, is it possible to cancel install

    10.11.5 on MacBook Air installation it worked for more than two hours, anyway to stop installing?

    Try to shut down the computer using the switch and restart. This may cause the installation ends.

  • A frozen (for more than an hour) when installing Win7 updates

    During the installation of updates during a restart, IQ506 froze, although few 'circle' still rotating, for more than an hour so far.  Message says not to put off, but nothing happens.  Where should I go from here, if I am not in power down?

    A few times just to give up and put off, I look at the HD indicator, if it goes 30 minutes without blinking I give him a strong power off, if the HD is flashing I will usually let it run all night

  • I try to activate my new 6s phone my old phone 4S. Almost everything seems to be transferred, but the wheel can now turn for more than 24 hours. Should I unplug and hope for the best?

    I've used icloud to transfer old 4 sec to 6 sec new phone but then tried to use the itunes backup. It has been run for more than 24 hours and seems to be stuck. Should I unplug the computer and stop the process?

    a bit of luck with your 6s still?

  • Averages for number of loops

    Hi all

    I have a code (attached) in which a triangular wave is supposed to a magnetic field of ramp up and down to very low frequency (0.1 Hz or low). Reading (X) vs keithley reading field (Y) represented by two random numbers generators must be taken in synchronization with the triangular wave point by point. I would be very grateful if you could help to achieve the following objectives:

    1. by taking the average for a few cycles. Basically, I would define the number of loops in the outer circle to the loop and the number of sampling inside everything in a loop and then take the average between the loops.

    (Data for data of loop2 +... + loop1) + data to loop n/n

    2. the averages should be written to the text file and at the same time, I hope I always get the full date in the file action.

    Thank you

    Hadi

    Assuming that you want to monitor the data happens, I would like to initialize several arrays, both to keep the x and are data and to keep the number of each 'package '.

    Now, simply add the new data to the existing elements while incrementing the corresponding number. Dividing by the count will give you the way to be represented graphically. Here's a simple rewrite. The "collection must match the size of the field ramp, so it shouldn't be a separate control, I think. Currently, you graph the two random channels. You would you rather them the two graphic vs of the field instead? You want front and back scans averaged individually or must they go to the same average with a half data table?

    You save operation still seems a little convoluted. How do you actually data to be organized in the final file?

    Here is a quick project to help you get started.

  • Laptop is blocked at the installation of 10 out of 17 Updtes for more than three hours

    Laptop last night quit unexpectedly. This morning when I started the machine, it was locked to the installation of 10 of the 17 updates for more than three hours. I tried to turn off the machine, but I still get the same message. How do I get this at the end to restart properly

    Hello
     
     
    1. remember you number updates that have been installed?
     
     
     
    First check to see if there are external devices attached to the computer, if so remove and check.
     
    Method 1.
    Let us run repair system at this stage, it might solve the problem.
    See the following articles for additional help and steps on startup repair.
    Startup Repair
    http://Windows.Microsoft.com/en-us/Windows7/products/features/Startup-Repair
    What are the system recovery options in Windows 7?
    http://Windows.Microsoft.com/en-us/Windows7/what-are-the-system-recovery-options-in-Windows-7
     
    Method 2.
    If the bows persists please verify if you are able to boot safe mode.
     
     
    If the problem exists not in Mode safe run mode startup minimum troubleshooting to find the root cause of the problem.
    How to troubleshoot a problem by performing a clean boot in Windows Vista or in Windows 7
    http://support.Microsoft.com/kb/929135
    Note: When the diagnosis is complete, don't forget to reset your computer to normal startup. Follow step 7 in the above article.
     
     
    Method 3.
    I recommend you to restore system using a Windows 7 DVD.

    Here's how:
    To open the Options menu system recovery using a system repair disc or a Windows 7 installation disc
    If your system is damaged and cannot access the menu system on your computer Recovery Options, you can access it using the Windows 7 installation disc or a system repair disc previously.
    To use this method, you need to restart (boot) your computer using the disk.
    a. Insert the disc.
    b. restart your computer using the power button on the computer.
    c. If prompted, press any key to start Windows from the installation disc.
    o If your computer is not configured to start from a CD or a DVD, see the documentation provided with your computer.
    d. choose your language settings, and then click Next.
    e. If you are using the Windows installation disc, click on repair your computer.
    f. Select the Windows installation you want to repair, and then click Next.
    g. in the System Recovery Options menu, click a tool to open it and then choose the system restore and check.
     
    If we are able to boot to the desktop now, I would ask you install the updates one by one andcheck the update is at the origin of the conflict.
     
     
     
    I hope this helps.

    Kind regards
    Support Microsoft Savan-

  • When I start the machine, continuous hard drive work for almost 1/2 hour, meanwhile if I open a program, the machine runs very slowly. Help solve the problem please

    I have wndow XP Home edition service pack 3 installed on my lap top. When I start the computer the hard drive continues to work for almost 1/2 hour; Meanwhile, if I open IE, or any program, the machine runs very slowly and I just can not open the program up until the drive hard light is off. Please help solve the problem

    How much RAM you have on your system? (Right click on "My Computer"-> properties)

    As a general rule, Windows XP does not work well if you have less than 1 GB or more of RAM.  What usually happens is that your RAM capacity is exceeded leading to overflow on virtual memory (the drive) to compensate for the need of RAM in the computer.  This causes your system to beat on your hard drive and slow down your system.

    If this is your problem, the options are to increase the RAM on your system or decrease the non-essential programs that launch at startup on your computer using a tool like Autoruns.

    HTH,
    JW

  • cannot access my hotmail account. have tried for more than 24 hours. now worried that everything has disappeared.

    No access to hotmail for more than 24 hours. Said they do maintenance and should not be more than an hour. Before be bleached, I had 9 unread messages, now when I sign it shows 0 next to the hotmail tab. What can I do? Nowhere to get after spending hours trying to find Hotmail and send requests on their forum.

    Submit all Live and Hotmail queries on the forum right here:

    Windows Live Solution Center
    http://windowslivehelp.com/

Maybe you are looking for

  • Lost my password synchronization

    I use Firefox for android and every now and then I clear Firefox completely app data because it starts to become slow for some reason any (even without addons). I just did this again an hour or two after a few months of no problems there. Since it's

  • How can I recover lost logo in bookmarks after the recent update?

    After your last auto update, I lost almost all of the logo in my favorite sites. Some have come to the time where I logged on the site, others not. How to get the back logo?

  • ASR backup on laptop Satellite series

    Since the machine has no internal floppy drive, I used a USB FDD to ASR backup. The main backup is located on a USB HDD and the recovery disc has been created in the USB FDD. When you try to use the ASR utility to restore the system to a new HARD dis

  • HP Photosmart 7520 series will not print from laptop

    Printer not print HP Pavilion dm4. Error message is the driver problem Microsoft Teredo Tunneling adapter with an error code of 10. Help, please!

  • computer slow ection off websites

    I have windows xp.  When I have x on a Web page or a Web site it will be anywhere from 3 to 10 seconds it disappears from the display.   It will last for a week or two, then it will change back and x out almost immediately and it will last about a we