Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id A5B339FC1CD for ; Thu, 28 Jun 2007 16:54:41 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 66337-07 for ; Thu, 28 Jun 2007 16:54:41 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id D9A2E9FBE08 for ; Thu, 28 Jun 2007 16:54:40 -0300 (ADT) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id 1312931435; Thu, 28 Jun 2007 21:54:39 +0200 (MET DST) From: =?iso-8859-1?q?Rodrigo_De_Le=F3n?= X-Newsgroups: pgsql.sql Subject: Re: SQL problem... Date: Thu, 28 Jun 2007 19:54:36 -0000 Organization: http://groups.google.com Lines: 25 Message-ID: <1183060476.696945.312620@q75g2000hsh.googlegroups.com> References: <89Tgi.8082$2X.3645@biebel.telenet-ops.be> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Complaints-To: groups-abuse@google.com In-Reply-To: <89Tgi.8082$2X.3645@biebel.telenet-ops.be> User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: q75g2000hsh.googlegroups.com; posting-host=200.75.231.230; posting-account=zGrw3Q0AAADU1m7dOiE5S6vTNtvJ7FdA To: pgsql-sql@postgresql.org X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200706/241 X-Sequence-Number: 28731 On Jun 28, 1:43 pm, "Bauhaus" wrote: > I have the following table Price: > > FuelID PriceDate Price > LPG 1/05/2007 0,2 > LPG 13/05/2007 0,21 > SPS 2/05/2007 1,1 > SPS 15/05/2007 1,08 > > And I have to make the following query: > > FuelID PriceDate_from PriceDate_To Price > LPG 1/05/2007 13/05/2007 0,2 > SPS 2/05/2007 15/05/2007 1,1 > LPG 13/05/2007 0,21 > SPS 15/05/2007 1,08 SELECT fuelid, pricedate AS pricedate_from , (SELECT MIN(pricedate) FROM price WHERE fuelid = s.fuelid AND pricedate > s.pricedate) AS pricedate_to, price FROM price s ORDER BY pricedate_from;