"Michael Richards" <michael@fastmail.ca> writes:
> I run a select sum(amount) from payments group by userid
> I need to modify this query so it returns the minimum, maximum and
> average sums. Is there any way I can do this?
You need two levels of grouping/aggregating to make that happen.
In 7.1 you can do it directly:
select min(amtsum), max(amtsum), avg(amtsum)
from (select sum(amount) as amtsum from payments group by userid) ss;
In prior versions you'd need to do the initial select into a temp
table and then select min/max/avg from that.
regards, tom lane