Re: Ranking? - Mailing list pgsql-novice

From Sjors
Subject Re: Ranking?
Date
Msg-id 001101c383bd$f11ad130$04a779d9@cc299057a
Whole thread Raw
In response to Ranking?  ("Sjors" <jkwast@freeler.nl>)
List pgsql-novice
Hi Manfred,

Sometimes the solution is right in front of you, but the cloud is to thick.
Thanks a lot, it worked like a charm. The reason I want this, is to have a
new type of index, so speed is not a issue and data file not big (just about
15000 records). I know, it's sounds silly.

Greetings Sjors


> >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: "Williams, Quinton L"
Date:
Subject: Some Simple Questions
Next
From: Doris Bernloehr
Date:
Subject: SQL Syntax problem