'GROUP BY' problem

From: Mariusz Czułada <manieq(at)idea(dot)net(dot)pl>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: 'GROUP BY' problem
Date: 2003-01-30 08:23:50
Message-ID: 200301300923.50894.manieq@idea.net.pl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi all,

I have a table:

CREATE TABLE tmp_server_perf_sum (
ts timestamp without time zone,
lock_count double precision,
cpu_busy_pct double precision,
transactions_rate double precision,
deadlock_count double precision
);

/* data from Sybase Historical Server */

I can:

SELECT
date_trunc('hour',ts),
min(cpu_busy_pct),
avg(cpu_busy_pct),
max(cpu_busy_pct)
FROM
tmp_server_perf_sum
GROUP BY
date_trunc('hour',ts);

and it works great. But 1h interval is to wide for me. On the over hand 1
minute is less than my samples in table. I'd like to group results for every
15 minues. I'd love to do it this way:

SELECT
date_trunc('15 minutes',ts),
min(cpu_busy_pct),
avg(cpu_busy_pct),
max(cpu_busy_pct)
FROM
tmp_server_perf_sum
GROUP BY
date_trunc('15 minutes',ts);

but unfortunately it is not working (I use 7.2.2, but IMHO it is not
important).

1. Can sb. help me with this query? How to make such groupping?

2. Do you think is it possible/needed to extend 'date_trunc' function to
support such options?

TIA

Mariusz Czulada

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Holger Klawitter 2003-01-30 08:36:48 Re: Firewalls and Postgres
Previous Message Holger Klawitter 2003-01-30 08:04:54 donations?