Re: Group by and aggregates

Поиск
Список
Период
Сортировка
От Sam Mason
Тема Re: Group by and aggregates
Дата
Msg-id 20041104172507.GG25775@sam.samason.me.uk
обсуждение исходный текст
Ответ на Group by and aggregates  ("Michael L. Hostbaek" <mich@the-lab.org>)
Список pgsql-sql
Michael L. Hostbaek wrote:
>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 ?

I think you need to join the table back on itself to get the total
for each part.  Not a very impressive incantation, but I'd do it 
in SQL like this:
 SELECT x.partno, x.status, y.tot, sum(x.qty) FROM my_table x, (   SELECT partno, MAX(cmup) as tot   FROM my_table
GROUPBY partno) y WHERE x.partno = y.partno GROUP BY x.partno, x.status, y.tot
 

Cheers, Sam


В списке pgsql-sql по дате отправления:

Предыдущее
От: Mischa Sandberg
Дата:
Сообщение: Re: CREATE TRIGGER ... FOR EACH STATEMENT
Следующее
От: faivrem@gmail.com (Mickael Faivre-Macon)
Дата:
Сообщение: Oracle to Postgres