Re: Rank

From: Martin Knipper <knipper(at)mk-os(dot)de>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Rank
Date: 2004-05-04 17:39:10
Message-ID: 4097D53E.6060400@mk-os.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Am 04.05.2004 18:47 schrieb Rob:

> Martin Knipper wrote:
>>Am 04.05.2004 16:11 schrieb george young:
>>>On Sun, 2 May 2004 02:22:37 +0800
>>>"Muhyiddin A.M Hayat" <middink(at)indo(dot)net(dot)id> threw this fish to the penguins:
>>>
>>>>I Have below table
>>>>
>>>>id | site_name | point
>>>>----+-----------+-------
>>>>1 | Site A | 40
>>>>2 | Site B | 90
>>>>3 | Site D | 22
>>>>4 | Site X | 98
>>>>
>>>>Would like to calc that Rank for each site, and look like
>>>>
>>>>id | site_name | point | rank
>>>>----+-----------+-------+------
>>>>1 | Site A | 40 | 3
>>>>2 | Site B | 90 | 2
>>>>3 | Site D | 22 | 4
>>>>4 | Site X | 98 | 1
>>>
>>>

[...]

>>
>>Another possibilty is to use a sequence:
>>
>>demo=# create temporary sequence ranking;
>>demo=# select *,nextval('ranking') as rank from yourTable order by
>>site_name asc;
>>
>
> wouldn't it have to be:
>
> select *, nextval('ranking') as rank
> from yourTable
> order by point desc;
>
> for the ranking to work?
>

Yes, you are right.
I guess I was a little confused with the ordering in the example
table Muhyiddin provided.

Greetings,
Martin

--
Martin Knipper
www : http://www.mk-os.de
Mail : knipper(at)mk-os(dot)de

In response to

  • Re: Rank at 2004-05-04 16:47:32 from Rob

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Huxton 2004-05-05 12:21:59 Test - please ignore
Previous Message Rob 2004-05-04 16:47:32 Re: Rank