Re: Reference to preceding row

From: Michel Cadot <micadot{at}altern{dot}org>
Date: Mon, 8 Jun 2009 18:11:53 +0200
Message-ID: <4a2d3846$0$16997$426a74cc_at_news.free.fr>


"Hans Mayr" <mayr1972_at_gmx.de> a écrit dans le message de news: 37711712-b230-49de-a976-ff092b0adc68_at_u10g2000vbd.googlegroups.com...
| Hello,
|
| Please look at the following example, where we measure the size of
| some kids:
|
| SELECT name, measurement_date, size FROM kids WHERE name = 'Bill'
| ORDER BY 1,2;
|
| Bill | 2007-01-01 | 90
| Bill | 2007-05-01 | 95
| Bill | 2007-12-01 | 101
|
| How can I rewrite the query that it gives me the growth since the last
| measurement? Like this:
|
| Bill | 2007-01-01 | 90 | (null)
| Bill | 2007-05-01 | 95 | 5
| Bill | 2007-12-01 | 101 | 6
|
| There are surely many ways to do this, but what is the best / easiest
| approach?
|
| Thanks and best,
|
| Hans

Using LAG function.

Regards
Michel Received on Mon Jun 08 2009 - 11:11:53 CDT

Original text of this message