|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
finding the difference from one row to anotherHi 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 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) |
|||||||||||||||||||||||