Re: sorting and grouping with min/max
От | Andreas Kretschmer |
---|---|
Тема | Re: sorting and grouping with min/max |
Дата | |
Msg-id | 20090301130849.GA9599@tux обсуждение исходный текст |
Ответ на | Re: sorting and grouping with min/max (Valentin Gjorgjioski <tinodj@mt.net.mk>) |
Ответы |
Re: sorting and grouping with min/max
|
Список | pgsql-novice |
Valentin Gjorgjioski <tinodj@mt.net.mk> 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 по дате отправления: