dbTalk Databases Forums  

Reference to preceding row

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss Reference to preceding row in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Hans Mayr
 
Posts: n/a

Default Reference to preceding row - 06-08-2009 , 10:56 AM






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

Reply With Quote
  #2  
Old   
Michel Cadot
 
Posts: n/a

Default Re: Reference to preceding row - 06-08-2009 , 11:11 AM






"Hans Mayr" <mayr1972 (AT) gmx (DOT) de> a écrit dans le message de news: 37711712-b230-49de-a976-ff092b0adc68...oglegroups.com...
Quote:
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

Reply With Quote
  #3  
Old   
Hans Mayr
 
Posts: n/a

Default Re: Reference to preceding row - 06-08-2009 , 11:34 AM



Thank you!

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.