Re: Ranking? - Mailing list pgsql-novice

From Manfred Koizar
Subject Re: Ranking?
Date
Msg-id 0vm6nv888s0c1pbkuqlg54gb0ggftnfori@email.aon.at
Whole thread Raw
In response to Ranking?  ("Sjors" <jkwast@freeler.nl>)
List pgsql-novice
On Thu, 25 Sep 2003 17:45:35 +0200, "Sjors" <jkwast@freeler.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

pgsql-novice by date:

Previous
From:
Date:
Subject: Re: Concurrency control
Next
From: Heath Tanner
Date:
Subject: Re: Function return type does not match