tags:

views:

22

answers:

2

Hi,

I measure the load on DNS servers every minute and store that into an SQL DB. I want to draw a chart of the load for the last 48 hours. That's 69120 (48*24*60) data points but my chart's only 800 pixels wide so to make things faster I would like my SQL query to return only ~800 data points.

It's seems to me like a pretty standard thing to do, but I've been searching the web and in books for such a thing for a while now and the closest I was able to find was a rolling average. What I'm looking for a more of a "segmented average": divide the 69120 data points in ~800 segments, then average each segment.

My SQL table is:

CREATE TABLE measurements (
  ip int, measurement_time int, queries int, query_time float
)

My query looks like this

SELECT measurement_time, ip, queries FROM measurements WHERE measurement_time>(time()-172800)

Thanks a lot!

+1  A: 

sum(queries) / 100 group by (measurement_time / 100)

Doug Currie
+2  A: 
DECLARE @interval int;
SET @interval = 87;
SELECT ip, AVG(queries), (measurement_time / @interval) AS interval
FROM measurements
WHERE measurement_time>(time()-172800)
GROUP BY (measurement_time / @interval)
ORDER BY (measurement_time / @interval);
Andrew
Wow! That was fast! Thanks to both of you (Andrew and Doug) for the quick replies!
Guillaume Filion