Re: maximum of sums - Mailing list pgsql-sql

From ThomasR
Subject Re: maximum of sums
Date
Msg-id 3C7221DF.9060907@wtal.de
Whole thread Raw
List 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






pgsql-sql by date:

Previous
From: Mark kirkwood
Date:
Subject: Transient Disk Usage Higher In 7.2 ?
Next
From: Laurent Patureau
Date:
Subject: SELECT with LEFT OUTER JOIN ON