Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 9D2D31337B7D for ; Wed, 17 Nov 2010 11:43:10 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 09154-05 for ; Wed, 17 Nov 2010 15:43:04 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 4C6181337B61 for ; Wed, 17 Nov 2010 11:43:03 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id oAHFgadO027015; Wed, 17 Nov 2010 10:42:36 -0500 (EST) To: "John Lister" cc: pgsql-sql@postgresql.org Subject: Re: obtaining difference between minimum value and next in size In-reply-to: <3BC753A3784F488F98304300B6E437FD@squarepi.com> References: <3BC753A3784F488F98304300B6E437FD@squarepi.com> Comments: In-reply-to "John Lister" message dated "Wed, 17 Nov 2010 15:11:32 +0000" Date: Wed, 17 Nov 2010 10:42:36 -0500 Message-ID: <27014.1290008556@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201011/37 X-Sequence-Number: 34775 "John Lister" writes: > Is it possible to obtain the difference between just the minimum price and the next one up per product, If you're using >= 8.4, try a window function. LEAD or LAG ought to do it. regards, tom lane