X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 27835D1D06F for ; Fri, 9 Apr 2004 22:31:26 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 21018-04 for ; Fri, 9 Apr 2004 22:31:22 -0300 (ADT) Received: from tht.net (vista.tht.net [216.126.88.2]) by svr1.postgresql.org (Postfix) with ESMTP id 2218DD1C9C8 for ; Fri, 9 Apr 2004 22:31:19 -0300 (ADT) Received: from [134.22.71.250] (dyn-71-250.tor.dsl.tht.net [134.22.71.250]) by tht.net (Postfix) with ESMTP id 006E776A23; Fri, 9 Apr 2004 21:31:27 -0400 (EDT) Subject: Re: SQL challenge--top 10 for each key value? From: Rod Taylor To: Greg Stark Cc: Josh Berkus , Jeff Boes , pgsql-sql@postgresql.org In-Reply-To: <87ad1kg4c2.fsf@stark.xeocode.com> References: <33af4fa4e4ec230574cefcff737ea40a@news.teranews.com> <87r7uyf3ki.fsf@stark.xeocode.com> <1081481466.56361.808.camel@jester> <200404090906.39541.josh@agliodbs.com> <87ad1kg4c2.fsf@stark.xeocode.com> Content-Type: text/plain Message-Id: <1081560594.56361.818.camel@jester> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.5 Date: Fri, 09 Apr 2004 21:29:55 -0400 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200404/88 X-Sequence-Number: 17463 On Fri, 2004-04-09 at 18:43, Greg Stark wrote: > Josh Berkus writes: > > > Rod, > > > > > Something along the lines of the below would accomplish what you want > > > according to spec. ROW_NUMBER() is a spec defined function. (6.10 of > > > SQL200N) > > > > Great leaping little gods! They added something called "row number" to the > > spec? > > > > Boy howdy, folks were right ... the ANSI committee really has completly blown > > off the relational model completely. > > If it's like Oracle's rownum then it's the row number of the *output*, not the > position on disk. So it's not entirely blowing off the relational model any > more than ORDER BY does. > > The weird thing is the number of cases where you want ORDER BY or rownum > inside subselects. Which the solution to the original question needed. It's not really like Oracles row num at all, though I suppose you can emulate rownum using it. The intention is that you will use it for "aggregates" like running totals, moving averages, counting, etc. http://www.devx.com/getHelpOn/10MinuteSolution/16573/1954?pf=true