Determining Rank

From: Don Drake <dondrake(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Determining Rank
Date: 2005-02-04 03:06:36
Message-ID: 6c21003b05020319061f8bce45@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I have a query that shows the top N count(*)'s.

So it's basically:

select some_val, count(*)
from big_table
group by some_val
order by count(*)
limit 50

Now, I would like to have the rank included in the result set. The
first row would be 1, followed by 2, etc. all the way to 50.

I can do this in PHP, but stuffing it into the DB query makes other
things easier.

Any ideas?

Thanks.

-Don

--
Donald Drake
President
Drake Consulting
http://www.drakeconsult.com/
http://www.MailLaunder.com/
312-560-1574

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Michael Fuhr 2005-02-04 04:21:19 Re: Determining Rank
Previous Message Edmund Bacon 2005-02-03 22:53:20 Re: getting back autonumber just inserted