X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 8DAE3D1B516 for ; Tue, 21 Oct 2003 07:18:44 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 06834-04 for ; Tue, 21 Oct 2003 04:18:15 -0300 (ADT) Received: from mta03bw.bigpond.com (mta03bw.bigpond.com [144.135.24.147]) by svr1.postgresql.org (Postfix) with ESMTP id 952DCD1B51A for ; Tue, 21 Oct 2003 04:18:12 -0300 (ADT) Received: from centauri.darrenmackay.com ([144.135.24.81]) by mta03bw.email.bigpond.com (iPlanet Messaging Server 5.2 HotFix 1.14 (built Mar 18 2003)) with SMTP id <0HN200BVX4DLTF@mta03bw.email.bigpond.com> for pgsql-sql@postgresql.org; Mon, 20 Oct 2003 23:05:45 +1000 (EST) Received: from cpe-203-45-149-167.qld.bigpond.net.au ([203.45.149.167]) by bwmam05bpa.bigpond.com(MAM REL_3_3_2d 44/6330594); Mon, 20 Oct 2003 23:05:45 +0000 Received: from [192.168.1.203] (helo=orion.mackay.local) by centauri.darrenmackay.com with esmtp (Exim 4.12) id 1ABZjF-0005LY-00 for pgsql-sql@postgresql.org; Mon, 20 Oct 2003 23:05:45 +1000 Received: from orion.mackay.local (unverified) by orion.mackay.local (Content Technologies SMTPRS 4.2.5) with ESMTP id for ; Mon, 20 Oct 2003 23:04:13 +1000 Date: Mon, 20 Oct 2003 23:04:13 +1000 From: email lists Subject: Re: date_trunc for 5 minutes intervals To: pgsql-sql@postgresql.org Message-id: <035C9F7CE28601428BBB5B051C9F77F2017851@orion.mackay.local> MIME-version: 1.0 X-MIMEOLE: Produced By Microsoft Exchange V6.0.6249.0 Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7BIT Content-class: urn:content-classes:message Thread-topic: [SQL] date_trunc for 5 minutes intervals Thread-index: AcOW81WZelEi924ySiaN/lNY32Lu+QAFFLvQ X-MS-Has-Attach: X-MS-TNEF-Correlator: X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200310/265 X-Sequence-Number: 15665 Hi, Thanks for the several replies both on and off the list. To be more specific, I am wanting to aggregate data to a 5/10/15 min interval. Currently, I am aggregating data that falls in hour / day / month / year periods for both count() and sum(). The sql I am currently using is: SELECT count(id) AS count, sum(conn_bytes) AS sum, hisec_port, conn_protocol, date_trunc('hour'::text, datetime) AS date_trunc FROM trafficlogs WHERE (conn_outbound = false) GROUP BY date_trunc('hour'::text, datetime), conn_protocol, hisec_port HAVING (count(*) = ANY ( SELECT count(*) AS count FROM trafficlogs GROUP BY hisec_port, date_trunc('hour'::text, datetime) ORDER BY count(*) DESC) ); Which produces: count sum hisec_portconn_protocol date_trunc 12 192 5,050 2003/09/17 00:00:00 11 176 5,050 2003/09/17 01:00:00 12 192 5,050 2003/09/17 02:00:00 11 176 5,050 2003/09/17 03:00:00 10 160 5,050 2003/09/17 04:00:00 - if you know of a more efficient way to do this than the sql above, pls let me know In my previous post I should have said I wanted to aggregating data in 5/10/15 min intervals in a similar manner to the above