Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: SQL problem...



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;




Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group