pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Don Drake <dondrake@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Determining Rank
Date: Thu, 3 Feb 2005 21:06:36 -0600
Message-ID: <6c21003b05020319061f8bce45@mail.gmail.com> (raw)

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



view thread (5+ messages)  latest in thread

Message-ID: <6c21003b05020319061f8bce45@mail.gmail.com>
Permalink:  ../6c21003b05020319061f8bce45@mail.gmail.com/
Also on:    postgresql.org/message-id/6c21003b05020319061f8bce45@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: dondrake@gmail.com
  Subject: Re: Determining Rank
  In-Reply-To: <6c21003b05020319061f8bce45@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox