pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: ThomasR <rehlich@wtal.de>
To: pgsql-sql@postgresql.org
Subject: Re: maximum of sums
Date: Tue, 19 Feb 2002 10:58:55 +0100
Message-ID: <3C7221DF.9060907@wtal.de> (raw)
References: <3c71e972$0$16639$afc38c87@news.optusnet.com.au>

Rob wrote:
> Howdy all!
> 

[snap table]

> 
> I have this so far:
> SQL> select
>   2     max (sumamt) as maximum
>   3  from
>   4     (select
>   5        sum (orders.quantity) as sumamt
>   6      from
>   7        orders
>   8      group by
>   9        orders.prod_no);
> 
>   MAXIMUM
> ---------
>        17
> 
> SQL>
> 
> But how can I get the matching prod_id?

perhaps with the limit-clause:

select prod_no, sum( quantity ) as sumq
   from orders
  group by prod_no
  order by sumq desc
  limit 1

But it fails, if you have two or more products with the same amount of 
orders


Thomas







view thread (3+ messages)  latest in thread

Message-ID: <3C7221DF.9060907@wtal.de>
Permalink:  ../3C7221DF.9060907@wtal.de/
Also on:    postgresql.org/message-id/3C7221DF.9060907@wtal.de

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: rehlich@wtal.de
  Subject: Re: maximum of sums
  In-Reply-To: <3C7221DF.9060907@wtal.de>

* 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