From: email lists <lists@darrenmackay.com>
To: pgsql-sql@postgresql.org
Subject: Re: date_trunc for 5 minutes intervals
Date: Mon, 20 Oct 2003 23:04:13 +1000
Message-ID: <035C9F7CE28601428BBB5B051C9F77F2017851@orion.mackay.local> (raw)
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: lists@darrenmackay.com
Subject: Re: date_trunc for 5 minutes intervals
In-Reply-To: <035C9F7CE28601428BBB5B051C9F77F2017851@orion.mackay.local>
References: <035C9F7CE28601428BBB5B051C9F77F2017851@orion.mackay.local>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox