Re: sorting and grouping with min/max

Поиск
Список
Период
Сортировка
Искать
От
Andreas Kretschmer
Тема
Re: sorting and grouping with min/max
Дата
Msg-id
20090301130849.GA9599@tux
Ответ на
Список
Дерево обсуждения
sorting and grouping with min/max vivawasser <d.piekarski@vivawasser.de>
Re: sorting and grouping with min/max Valentin Gjorgjioski <tinodj@mt.net.mk>
Re: sorting and grouping with min/max Andreas Kretschmer <akretschmer@spamfence.net>
Re: sorting and grouping with min/max Valentin Gjorgjioski <tinodj@mt.net.mk>
Re: sorting and grouping with min/max "A. Kretschmer" <andreas.kretschmer@schollglas.com>
Valentin Gjorgjioski  wrote:
>> i'm looking for a query that returns one row for each player with the
>> smallest cmd_nr value. after several hours i figured out the following
>> query
>>
>> SELECT * FROM command_queue GROUP BY id, params, player, cmd_nr, date
>> HAVING (player, cmd_nr) IN (SELECT player, MIN(cmd_nr) FROM
>> command_queue GROUP BY player)
>
> well... for sure it would be simpler if you say
>
> SELECT * FROM command_queue where
> (player, cmd_nr) IN (SELECT player, MIN(cmd_nr) FROM command_queue GROUP  
> BY player)
>
> But, can be even simpler? I hate subqueries...

Maybe it is faster with an JOIN instead the IN(...), other solution:
wait for 8.4 windowing functions...


Andreas
-- 
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect.                              (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly."   (unknown)
Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°
В списке pgsql-novice по дате отправления
От: Valentin Gjorgjioski
Дата:
От: Valentin Gjorgjioski
Дата:
FAQ