Group by and aggregates - Mailing list pgsql-sql

From Michael L. Hostbaek
Subject Group by and aggregates
Date
Msg-id 20041104165430.GD94770@mich2.itxmarket.com
Whole thread Raw
Responses Re: Group by and aggregates  (Michael Fuhr <mike@fuhr.org>)
Re: Group by and aggregates  (Edmund Bacon <ebacon@onesystem.com>)
Re: Group by and aggregates  (Franco Bruno Borghesi <franco@akyasociados.com.ar>)
Re: Group by and aggregates  (Oliver Elphick <olly@lfix.co.uk>)
Re: Group by and aggregates  (Sam Mason <mason@f2s.com>)
List pgsql-sql
List,

I've got a table looking something like this:

my_tablesome_id int bla bla,partno varchar(100),status varchar(100),cmup numeric(14,2),qty int

Here a small sample of contents in my table:

some_id    partno    status        cmup    qty
1    test1    stock        10.00    15
2    test2    incoming    12.00    10
3    test1    incoming    15.00    60
4    test1    incoming    14.00    11


My SQL select statement will then group together partno, status and
aggregate sum(qty) and max(cmup). This is all good and nice.

My result will look something like this:

partno    status        cmup    qty
test1    stock        10.00    15
test1    incoming    15.00    71
test2    incoming    12.00    10

Now, I need the first line to say "15.00" in the cmup field. That is,
stock and incoming are obviously not being grouped, but since it's the
same partno I'd like somehow to show the highest cmup. Is there some
black SQL voodoo that'll achieve this ?

TIA,

--
Best Regards,Michael L. Hostbaek
*/ PGP-key available upon request /*

pgsql-sql by date:

Previous
From: sad
Date:
Subject: Re: CREATE TYPE
Next
From: SZŰCS Gábor
Date:
Subject: Delayed result from another connection