Re: SQL problem...

From: Rodrigo De León <rdeleonp(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: SQL problem...
Date: 2007-06-28 19:54:36
Message-ID: 1183060476.696945.312620@q75g2000hsh.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Jun 28, 1:43 pm, "Bauhaus" <niemandh(dot)(dot)(dot)(at)pandora(dot)be> 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;

Browse pgsql-sql by date

  From Date Subject
Next Message A. Kretschmer 2007-06-29 04:57:37 Re: record fields as columns in reports
Previous Message Andreas Joseph Krogh 2007-06-28 16:14:19 Re: Is index usage in LIKE-queries with UTF-8 implemented in PG-8.3 ?