Re: Ranking?

From: Manfred Koizar <mkoi-pg(at)aon(dot)at>
To: "Sjors" <jkwast(at)freeler(dot)nl>
Cc: <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Ranking?
Date: 2003-09-25 21:29:19
Message-ID: 0vm6nv888s0c1pbkuqlg54gb0ggftnfori@email.aon.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Thu, 25 Sep 2003 17:45:35 +0200, "Sjors" <jkwast(at)freeler(dot)nl> wrote:
>now I want to have this:
>
>id name data rank
>1 sully 567 2
>2 sully 789 1
>3 sully 456 3
>4 denan 890 1
>5 denan 678 2

SELECT id, name, data, (SELECT count(*) + 1
FROM tbl AS tmp
WHERE tmp.name = tbl.name
AND tmp.data > tbl.data) AS rank
FROM tbl;

should get you going but might perform horribly without an index on
name ...

Servus
Manfred

In response to

  • Ranking? at 2003-09-25 15:45:35 from Sjors

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Heath Tanner 2003-09-25 22:28:37 Re: Function return type does not match
Previous Message radha.manohar 2003-09-25 20:48:22 Re: Concurrency control