Received: from mail.rdc1.az.home.com (imail@ha1.rdc1.az.home.com [24.1.240.66]) by hub.org (8.10.1/8.10.1) with ESMTP id e8JFZos48005 for ; Tue, 19 Sep 2000 11:35:50 -0400 (EDT) Received: from renne ([24.16.143.93]) by mail.rdc1.az.home.com (InterMail vM.4.01.02.00 201-229-116) with SMTP id <20000919153549.KJM12685.mail.rdc1.az.home.com@renne>; Tue, 19 Sep 2000 08:35:49 -0700 From: "Stuart Foster" To: , Subject: RE: sum of agreggates in one SELECT? Date: Tue, 19 Sep 2000 08:28:27 -0700 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0) X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 In-Reply-To: <20000919125859.A2802@styx> Importance: Normal X-Archive-Number: 200009/134 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@hub.org [mailto:pgsql-sql-owner@hub.org]On Behalf Of Louis-David Mitterrand Sent: Tuesday, September 19, 2000 3:59 AM To: pgsql-sql@postgresql.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@apartia.org - http://www.apartia.org