Re: select max()

From: Alexander Farber <alexander(dot)farber(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: select max()
Date: 2010-11-30 10:47:08
Message-ID: AANLkTimoJoDokTX5wyHA6HQ0W7_enCjm4s+0kc8Uaus7@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Ok, it is

# select id from pref_money where money in (select max(money) from
pref_money group by yw);
id
----------------
DE8048
VK91770810
DE7115
OK252342810632
OK228530000997
(5 rows)

And to see how many times a player has won is:

# select count(id) from pref_money where id='DE7115' and money in
(select max(money) from pref_money group by yw);
count
-------
1
(1 row)

My only problem is how to prevent false positives,
when the money value in 2 months is the same and
in 1 of the months it is the max value, but in the
other month it is not the max value and has another id.
Then the latter id will be falsely indicated as "winner"...

Regards
Alex

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Simon Riggs 2010-11-30 12:26:57 Re: [GENERAL] column-level update privs + lock table
Previous Message Andrus 2010-11-30 10:41:14 how to increase upsize speed