pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stuart Foster <stuartafoster@home.com>
To: ldm@apartia.ch
To: pgsql-sql@postgresql.org
Subject: RE: sum of agreggates in one SELECT?
Date: Tue, 19 Sep 2000 08:28:27 -0700
Message-ID: <LOBBJCEMCNNHMFAJGBOPKEBKCEAA.stuartafoster@home.com> (raw)
In-Reply-To: <20000919125859.A2802@styx>

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




view thread (6+ messages)  latest in thread

Message-ID: <LOBBJCEMCNNHMFAJGBOPKEBKCEAA.stuartafoster@home.com>
Permalink:  ../LOBBJCEMCNNHMFAJGBOPKEBKCEAA.stuartafoster@home.com/
Also on:    postgresql.org/message-id/LOBBJCEMCNNHMFAJGBOPKEBKCEAA.stuartafoster@home.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: stuartafoster@home.com, ldm@apartia.ch
  Subject: Re: sum of agreggates in one SELECT?
  In-Reply-To: <LOBBJCEMCNNHMFAJGBOPKEBKCEAA.stuartafoster@home.com>
  References: <20000919125859.A2802@styx> <LOBBJCEMCNNHMFAJGBOPKEBKCEAA.stuartafoster@home.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox