Re: interval questions
| От | Ed Loehr |
|---|---|
| Тема | Re: interval questions |
| Дата | |
| Msg-id | 39372825.FF359FF9@austin.rr.com обсуждение исходный текст |
| Ответ на | interval questions (Michael Blakeley <mike@blakeley.com>) |
| Ответы |
Re: interval questions
|
| Список | pgsql-general |
Michael Blakeley wrote: > > CREATE TABLE EVENTS( stamp date, id varchar(16), event varchar(128) ); > > 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 > Interesting problem. Would this do it? select into temp_age id, sum(age(stamp)) as age_sum, count(id) from EVENTS group by id; followed by select avg(age_sum/count) from temp_age; Regards, Ed Loehr
В списке pgsql-general по дате отправления: