Select Previous Row Values

Please support our MS SQL advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Nov 2006
Posts: 32
Reputation: dmmckelv is an unknown quantity at this point 
Solved Threads: 0
dmmckelv dmmckelv is offline Offline
Light Poster

Select Previous Row Values

 
0
  #1
Jul 18th, 2008
Is there a keyword in SQL that would allow you to select a value from a field in the previous row? I am looking for something that would give me the speed field value for the row before:
  1. SELECT min(Parsed.Time), [Parsed.Number]
  2. FROM Parsed
  3. GROUP BY [Parsed.Rev Number]
Last edited by dmmckelv; Jul 18th, 2008 at 4:58 am. Reason: more specific
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 18
Reputation: wujtehacjusz is an unknown quantity at this point 
Solved Threads: 7
wujtehacjusz's Avatar
wujtehacjusz wujtehacjusz is offline Offline
Newbie Poster

Re: Select Previous Row Values

 
0
  #2
Jul 18th, 2008
You can always use join two tables using row_number()...
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 32
Reputation: dmmckelv is an unknown quantity at this point 
Solved Threads: 0
dmmckelv dmmckelv is offline Offline
Light Poster

Re: Select Previous Row Values

 
0
  #3
Jul 18th, 2008
Originally Posted by wujtehacjusz View Post
You can always use join two tables using row_number()...
My rows are not numbered. Any other suggestions?

Thanks!
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 296
Reputation: tesuji is on a distinguished road 
Solved Threads: 42
tesuji tesuji is offline Offline
Posting Whiz in Training

Re: Select Previous Row Values

 
1
  #4
Jul 20th, 2008
Hello dmmckelv,

When Edgar Frank Codd invited relational databases his primary idea was to found it on
logic algebra and set theory. The rows of relational tables (aka relations) are sets. Therefore, there aren't duplicate rows nor any particular order of rows. From this point of view, "I am looking for something that would give me the speed field value for the row before" is rather irrelevant.

However, to put any meaningful signification on it, your table must already have a column
which allows such an ordering, for example date, timestamp or auto-increment numbers.
If you don't have such special column (or set of columns) within a table, it is impossible to determine the predecessor of a specific row because the today predecessor could be the successor row tomorrow (e.g. due to inserting and deleting rows in the meantime).

To cut a long story short, what's that special column of your table to get particularly ordered rows? You may also post the creating statement of your table.

-----
tesu
Information is moving—you know, nightly news is one way, of course, but it's also moving through the blogosphere and through the Internets. I promise you I will listen to what has been said here, even though I wasn't here. Ann and I will carry out this equivocal message to the world. I'm the master of low expectations.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC