comparing times from rows in a group

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bwhite
    New Member
    • Aug 2013
    • 1

    comparing times from rows in a group

    I have items in a group.
    Each item has a time stamp.
    I'm looking for gaps of two seconds or more.

    I can order them by GroupId and ItemId and manually search for gaps.

    The gap for ItemA is defined as ItemB.Created - ItemA.Created.

    How do I query to find the length of the gap for each item?

    The gap for the last item is obviously undefined.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You will need to join the table to itself on a ranking column. How you create the column will depend on what version of SQL Server you have. If you're lucky, you can just use the row_number() function.

    Comment

    Working...