Re: interval questions

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: interval questions
Дата
Msg-id 9897.959913760@sss.pgh.pa.us
обсуждение исходный текст
Ответ на interval questions  (Michael Blakeley <mike@blakeley.com>)
Список pgsql-general
Michael Blakeley <mike@blakeley.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

В списке pgsql-general по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: query optimiser changes 6.5->7.0
Следующее
От: Alfred Perlstein
Дата:
Сообщение: Re: interval questions