Re: Group by 15 Minute Steps - Mailing list pgsql-sql

From Jonathan Daugherty
Subject Re: Group by 15 Minute Steps
Date
Msg-id 20050321043010.GC20336@vulcan.cprogrammer.org
Whole thread Raw
In response to Group by 15 Minute Steps  (Martin Knipper <martin@mk-os.de>)
List pgsql-sql
# Usally, the steps between each entries is 300 seconds.  How can I
# group by by 15, 30, 45 minutes so that i can get averages over the
# specified timeframe?

For 15-minute data, I'd compute the "quadrant" of each record and
group by the quadrant number.  Anything that occurs from :00 to :14 is
in quadrant zero, :15 - :29 is quadrant 1, etc., yielding quadrants
0-3.

mydb> SELECT (time / (15 * 60)) AS quadrant, SUM(ifinoctets) FROM
mytable GROUP BY quadrant ORDER BY quadrant;

Divide the time by 60 to get minutes and 15 to get quadrants.  You can
see how to extend this for other intervals.

--  Jonathan Daugherty Command Prompt, Inc. - http://www.commandprompt.com/ PostgreSQL Replication & Support Services,
(503)667-4564
 



pgsql-sql by date:

Previous
From: "Hermann Draeger"
Date:
Subject: tablename as function parameter
Next
From: "mroyce@gmail.com"
Date:
Subject: timestamp precision - can I control precision at select time or set for all time?