X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 7524B8B9F8A for ; Fri, 4 Feb 2005 03:06:42 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 52596-07 for ; Fri, 4 Feb 2005 03:06:36 +0000 (GMT) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.207]) by svr1.postgresql.org (Postfix) with ESMTP id C455F8B9F7A for ; Fri, 4 Feb 2005 03:06:38 +0000 (GMT) Received: by wproxy.gmail.com with SMTP id 67so406794wri for ; Thu, 03 Feb 2005 19:06:36 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:mime-version:content-type:content-transfer-encoding; b=AaxQUhHnrrtfxhTz9aZIieQGOg7iiyIv2Rc/rypf1htl7OhUKngBJt1qo2bF/R3GP8b3n5ioeG4GLeky9I2k1VZb1kDglvcboWDOiuKpUpj5ORTFisqk/vRjHwfTju14Y/EWlBUhv9DmsOViF6UiZknHKdC6/EQ408wN1AR3S1g= Received: by 10.54.46.10 with SMTP id t10mr15212wrt; Thu, 03 Feb 2005 19:06:36 -0800 (PST) Received: by 10.54.4.71 with HTTP; Thu, 3 Feb 2005 19:06:36 -0800 (PST) Message-ID: <6c21003b05020319061f8bce45@mail.gmail.com> Date: Thu, 3 Feb 2005 21:06:36 -0600 From: Don Drake Reply-To: Don Drake To: pgsql-sql@postgresql.org Subject: Determining Rank Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.024 tagged_above=0 required=5 tests=AWL, RCVD_BY_IP X-Spam-Level: X-Archive-Number: 200502/83 X-Sequence-Number: 20194 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