Archives of the TeradataForum
Message Posted: Thu, 20 Aug 2015 @ 08:58:18 GMT
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.
|Copyright 2016 - All Rights Reserved|
|Last Modified: 28 Jun 2020|