Re: Built in Functions use with recordsets

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Built in Functions use with recordsets
Дата
Msg-id 4854.975598761@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Built in Functions use with recordsets  ("Gordan Bobic" <gordan@freeuk.com>)
Ответы RE: Built in Functions use with recordsets  ("Alistair Hopkins" <alistair@berthengron.co.uk>)
Список pgsql-general
"Gordan Bobic" <gordan@freeuk.com> writes:
> over a certain set of records. In effect, I want to do something like:

> SELECT somefield
> FROM sometable
> WHERE otherfield = 'criteria'
> ORDER BY thirdfield
> LIMIT 10

> and then do an avg(somefield).

> Can this be done without using temp tables, in a single query?

Not if the order by/limit are essential to selecting the rows you need
to average over.  At least not in 7.0 ... in 7.1 this'll work:

SELECT avg(somefield) FROM
(SELECT somefield FROM sometable ... LIMIT 10) t1;

For the moment a temp table is the way to go.

            regards, tom lane

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

Предыдущее
От: Doug Semig
Дата:
Сообщение: Re: Database cluster?
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Can PostGreSQL handle 100 user database?