Re: [SQL] finding a maximum or minimum sum

2001-06-11 Thread Michael Richards
Prfect! This is exactly what I needed. Didn't know postgres supported subselects like that. Thanks. -Michael > 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 int

Re: [SQL] finding a maximum or minimum sum

2001-06-11 Thread Tom Lane
"Michael Richards" <[EMAIL PROTECTED]> 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 y

[SQL] finding a maximum or minimum sum

2001-06-11 Thread Michael Richards
I have a table that looks like so: userid | amount --- 1 | $500 2 | $400 2 | $-100 2 | $10 3 | $10 3 | $10 I run a select sum(amount) from payments group by userid userid | sum -- 1| $500 2| $310 3| $20 I need to mo