
152 PUZZLE 37 A MOVING AVERAGE
PUZZLE
37 A MOVING AVERAGE
You are collecting statistical information stored by the quarter hour.
What your customer wants is to get information by the hour—not on the
hour. That is, we don’t want to know what the load was at 00:00 hours, at
01:00 hours, at 02:00 hours, and so forth. We want the average load for
the first four quarter hours (00:00, 00:15, 00:30, 00:45), for the next
four quarter hours (00:15, 00:30, 00:45, 01:00), and so forth. This is
called a moving average, and we will assume that the sample table looks
like this:
CREATE TABLE Samples
(sample_time TIMESTAMP NOT NULL PRIMARY KEY,
load REAL NOT NULL); ...