Received: from styx.apartia.int (postfix@r34m39.cybercable.tm.fr [195.132.34.39]) by hub.org (8.10.1/8.10.1) with ESMTP id e8JAxFs16990 for ; Tue, 19 Sep 2000 06:59:15 -0400 (EDT) Received: by styx.apartia.int (Postfix, from userid 1000) id 462C45AF1; Tue, 19 Sep 2000 12:58:59 +0200 (CEST) Date: Tue, 19 Sep 2000 12:58:59 +0200 From: Louis-David Mitterrand To: pgsql-sql@postgresql.org Subject: sum of agreggates in one SELECT? Message-ID: <20000919125859.A2802@styx> Reply-To: ldm@apartia.ch Mail-Followup-To: pgsql-sql@postgresql.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i X-Archive-Number: 200009/133 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