| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
|---|---|
| To: | Michael Blakeley <mike(at)blakeley(dot)com> |
| Cc: | pgsql-general(at)postgreSQL(dot)org |
| Subject: | Re: interval questions |
| Date: | 2000-06-02 02:42:40 |
| Message-ID: | 9897.959913760@sss.pgh.pa.us |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
Michael Blakeley <mike(at)blakeley(dot)com> writes:
> I'm trying to find the average age of the records. I've gotten as far as:
> SELECT DISTINCT ON(id) age(stamp) FROM EVENTS;
> Now, I need the DISTINCT ON(id), but that means I can't simply avg() the age:
> ERROR: Attribute events.id must be GROUPed or used in an
> aggregate function
You don't say *why* you need DISTINCT ON, or exactly what output you
are hoping to get (presumably not a straight average over all the table
entries) ... but perhaps something like
SELECT id, avg(age(stamp)) FROM events GROUP BY id;
is what you need?
regards, tom lane
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Alfred Perlstein | 2000-06-02 02:48:28 | Re: interval questions |
| Previous Message | Tom Lane | 2000-06-02 02:39:47 | Re: query optimiser changes 6.5->7.0 |