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

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

              http://archives.postgresql.org

Reply via email to