Home Page for the TeradataForum

Archives of the TeradataForum

Message Posted: Thu, 20 Aug 2015 @ 08:58:18 GMT

  <Prev Next>  
Next> Last>>  

Subj:   Query to return records which are in sequence
From:   Gupta, Vipin


I need help to write a query. Please see details below.

I have a table which records hourly value, and data looks like following:

     Hour      value
     0          23
     1          32
     2          44
     3          68
     5          70
     6          65
     7          81

I want to calculate average of "value" collected for last consecutive hours (maximum 6 hours).

In above data, hour 4 is missing.

Query should be able to do the average for values which were collected consecutively and the number of hours for which average was calculated. So query should give me = sum(23+32+44+68)/count(hour) and count(hour) should be 4 (since we are averaging 4 hours)

In short, query should return only those records which have consecutive hours and break whenever hours are not continuous.



  <Prev Next>  
Next> Last>>  
  Top Home Privacy Feedback  
Copyright for the TeradataForum (TDATA-L), Manta BlueSky    
Copyright 2016 - All Rights Reserved    
Last Modified: 24 Jul 2020