select max()

Поиск
Список
Период
Сортировка
От Alexander Farber
Тема select max()
Дата
Msg-id AANLkTinRgyY0LdRvqN7sywqO60s+gKkmyJMOJSYiB2Gj@mail.gmail.com
обсуждение исходный текст
Ответы Re: select max()
Список pgsql-general
Hello,

I have this table where I store player results for each week:

# select * from pref_money limit 5;
       id       | money |   yw
----------------+-------+---------
 OK32378280203  |   -27 | 2010-44
 OK274037315447 |   -56 | 2010-44
 OK19644992852  |     8 | 2010-44
 OK21807961329  |   114 | 2010-44
 FB1845091917   |   774 | 2010-44
(5 rows)

I'm trying to find the winners for each week and
also how many times the player has won,
so that I can display a number of medals
at his or her profile page.

I'm trying:

# select id, money from pref_money where money in
   (select max(money) from pref_money group by yw);
       id       | money
----------------+-------
 DE8048         |  3927
 VK91770810     |  6133
 DE7115         |  6655
 OK252342810632 |  8053
 OK228530000997 |  1013
(5 rows)

But I'm worried that "where in" will return false positives
(for the cases with the same money values)
and also I don't know how to count the repeated winners?

Thank you
Alex

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

Предыдущее
От: Craig Ringer
Дата:
Сообщение: Re: PostgreSQL hanging on new connections?
Следующее
От: Dusan Misic
Дата:
Сообщение: Re: PostgreSQL hanging on new connections?