Grouping aggregate functions

Поиск
Список
Период
Сортировка
От Richard Connamacher
Тема Grouping aggregate functions
Дата
Msg-id 9ECBA3BE-1CDD-4C2F-A7F6-B4C1AB47D402@indieimage.com
обсуждение исходный текст
Ответы Re: Grouping aggregate functions  (Martijn van Oosterhout <kleptog@svana.org>)
Список pgsql-general
Hey all,

I'm new on this list, and have been playing with Postgres a lot this
week. (Love it, by the way.)

I've got a question, if anyone can help me out. I know how to use an
aggregate function to, say, find the lowest price ever listed for a
product. I also know how to combine that with a SELECT ... GROUP BY
statement to find, say, the lowest price reported for each month.
Now, what if I want to find the *average* of all the lowest prices
for each month? Plopping that SELECT statement inside parentheses and
inside an "avg( )" function produces an error.

What I'd love to do, and which creates an error, would be something
like:

SELECT avg( ( SELECT min(price) FROM weekly_supply_prices GROUP BY
month ) )

The error I get is: "ERROR:  more than one row returned by a subquery
used as an expression" (to state the obvious). If I don't double up
the quotes I get a syntax error.

Anyone have any idea how to do this? Or do I have to compute the
average in another program?

Thanks!
Richard

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

Предыдущее
От: Tino Wildenhain
Дата:
Сообщение: Re: PostgreSQL makes me lie
Следующее
От: Martijn van Oosterhout
Дата:
Сообщение: Re: Grouping aggregate functions