Aggregate time data on half hour interval

From: Lars <lars(at)sscsinc(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Aggregate time data on half hour interval
Date: 2000-07-20 05:00:16
Message-ID: Pine.BSF.4.10.10007192132170.9230-100000@maximillion.sscsinc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I am looking for a way to aggregate timestamped data on a half hour
interval, not just by the hour or minute. Suppose I have a table composed
of:

Date | Time | Data
-----------+----------+------
1999-12-19 | 10:00:00 | 76
1999-12-19 | 10:15:00 | 72
1999-12-19 | 10:30:00 | 77
1999-12-19 | 10:45:00 | 71
1999-12-19 | 11:00:00 | 74
1999-12-19 | 11:15:00 | 78

I can aggregate by the hour without problem:
SELECT Date, date_trunc('hour', Time) AS HOUR, SUM(Data)
FROM Table
GROUP BY Date, HOUR;

What I would like to do though is aggregate by each half hour or maybe
even 20 minutes. Does anyone know a good way to do this?

Thanks in advance,

-Lars

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2000-07-20 05:20:51 Re: Aggregate time data on half hour interval
Previous Message Chris Bitmead 2000-07-20 04:56:42 Re: [HACKERS] Re: PRIMARY KEY & INHERITANCE (fwd)