Re: Group by 15 Minute Steps

From: Jonathan Daugherty <cygnus(at)cprogrammer(dot)org>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Group by 15 Minute Steps
Date: 2005-03-21 04:30:10
Message-ID: 20050321043010.GC20336@vulcan.cprogrammer.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Jonathan Daugherty 2005-03-21 05:08:20 Re: tablename as function parameter
Previous Message tgl 2005-03-20 16:21:11 Re: Mail Authentification