Re: maximum of sums

From: ThomasR <rehlich(at)wtal(dot)de>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: maximum of sums
Date: 2002-02-19 09:58:55
Message-ID: 3C7221DF.9060907@wtal.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Laurent Patureau 2002-02-19 10:00:59 SELECT with LEFT OUTER JOIN ON
Previous Message Christopher Kings-Lynne 2002-02-19 09:03:29 Re: [SQL] Transient Disk Usage Higher In 7.2 ?