Reference to preceding row

From: Hans Mayr <mayr1972_at_gmx.de>
Date: Mon, 8 Jun 2009 08:56:25 -0700 (PDT)
Message-ID: <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 Received on Mon Jun 08 2009 - 10:56:25 CDT

Original text of this message