Home All Groups Group Topic Archive Search About

finding the difference from one row to another

Author
20 Jan 2006 1:03 PM
polluxopera
Hi there...

I have a table with this data:

id       entered_time
1        2:38:33 PM
2        2:54:45 PM
3        3:03:23 PM

What I need to do is figure out the time difference between the
entered_time values in row 1 and row 2, row 2 and row 3, etc., but I'm
not sure how to do this.  Any suggestions?

Thanks!
Mark

Author
20 Jan 2006 1:16 PM
markc600
You haven't supplied any DDL so this is untested.


SELECT t1.id AS Start,
       t2.id AS Finish,
       DATEDIFF(minute,t1.entered_time,t2.entered_time) as TimeDiff
FROM sometable t1
INNER JOIN sometable t2 ON t2.id=(SELECT MIN(t3.id)
                                  FROM sometable t3
                                  WHERE t3.id>t1.id)
Author
20 Jan 2006 1:38 PM
Mark
Actually...I'm running Access 2000.  Just realized I posted in the
wrong news group. :-)

For what it's worth...when I try the above code, I'm getting an error
message.

AddThis Social Bookmark Button