Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2003
    Posts
    225

    Unanswered: count duration between records

    is it possible to count the time between records? example

    Table set up:

    LogID
    StartTime
    StopTime
    ProblemCode

    Example records:

    Id -------> StartTime ------> StopTime--------> ProblemCode

    1 -------->06/10/05 10:00 -> 06/10/05 10:02 -> A101
    2 -------->06/10/05 11:00 -> 06/10/05 11:02 -> A131

    i want to count the time elapsed between, ID 1 ending and ID 2 starting, can ido this?

    if so how..

    the duration i am looking for in this case would be 58 mins

    cheers

    Andy

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    select r1.Id       as R1_ID
         , r1.StopTime
         , r2.Id       as R2_ID
         , r2.StartTime
         , r2.StartTime-r1.StopTime as Duration
      from daTable as r1
    inner
      join daTable as r2
        on r2.StartTime
         = ( select min(StartTime)
               from daTable
              where StartTime > r1.StopTime )
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Mar 2003
    Posts
    225
    many thanks,

    i have tried entering this into the sql to see how it works but i cant get it to run,

    anychance you can take a look please

    cheers

    Andy
    Attached Files Attached Files

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    nope, no chance at all, i can't read your mdb
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    perhaps it's the ON condition

    you could try the same query like this:
    Code:
    select r1.Id       as R1_ID
         , r1.StopTime
         , r2.Id       as R2_ID
         , r2.StartTime
         , r2.StartTime-r1.StopTime as Duration
      from daTable as r1
         , daTable as r2
     where r2.StartTime
         = ( select min(StartTime)
               from daTable
              where StartTime > r1.StopTime )
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •