Search Postgresql Archives
Grouping aggregate functions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
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
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]
[Postgresql Jobs]
[Postgresql Admin]
[Postgresql Performance]
[Linux Clusters]
[PHP Home]
[PHP on Windows]
[Kernel Newbies]
[PHP Classes]
[PHP Books]
[PHP Databases]
[Postgresql & PHP]
[Yosemite]