From: | "Stuart Foster" <stuartafoster(at)home(dot)com> |
---|---|
To: | <ldm(at)apartia(dot)ch>, <pgsql-sql(at)postgresql(dot)org> |
Subject: | RE: sum of agreggates in one SELECT? |
Date: | 2000-09-19 15:28:27 |
Message-ID: | LOBBJCEMCNNHMFAJGBOPKEBKCEAA.stuartafoster@home.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Could it be that the first query is using max which will only return the max
for b.lot and b.price..
so maybe.
select sum(max(b.lot))as quantity, max(b.price) as price from bid b, person
p where b.auction_id = 84 and p.id = b.person_id ;
Just a thought.
-----Original Message-----
From: pgsql-sql-owner(at)hub(dot)org [mailto:pgsql-sql-owner(at)hub(dot)org]On Behalf
Of Louis-David Mitterrand
Sent: Tuesday, September 19, 2000 3:59 AM
To: pgsql-sql(at)postgresql(dot)org
Subject: [SQL] sum of agreggates in one SELECT?
Hello,
I have the following query/result:
auction=# select max(b.lot) as quantity,max(b.price) as price,p.login from
bid b, person p where b.auction_id = 84 and p.id = b.person_id group by
p.login order by max(price);
quantity | price | login
----------+-------+-----------
1 | 5000 | papy
12 | 5750 | cunctator
8 | 6000 | vindex
(3 rows)
Now I would like to sum() all results from the quantity column and
return it with one SELECT statement. Is that possible?
I am trying:
auction=# select sum(b.lot) from bid b, person p where b.auction_id = 84 and
p.id = b.person_id ;
sum
-----
52
(1 row)
But this is wrong because it sums all quantities. I don't know how to
apply a valid WHERE clause in that case.
Thanks in advance for any help, cheers,
--
Louis-David Mitterrand - ldm(at)apartia(dot)org - http://www.apartia.org
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2000-09-19 17:27:48 | Re: sum of agreggates in one SELECT? |
Previous Message | Louis-David Mitterrand | 2000-09-19 10:58:59 | sum of agreggates in one SELECT? |