select max() - Mailing list pgsql-general

From Alexander Farber
Subject select max()
Date
Msg-id AANLkTinRgyY0LdRvqN7sywqO60s+gKkmyJMOJSYiB2Gj@mail.gmail.com
Whole thread Raw
Responses Re: select max()
List 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 by date:

Previous
From: Craig Ringer
Date:
Subject: Re: PostgreSQL hanging on new connections?
Next
From: Dusan Misic
Date:
Subject: Re: PostgreSQL hanging on new connections?