How to get the differencee between frist row and last row in sql server

  • I have table e.g

    ID START_TIME END_TIME STATUS

    1 2011-10-09 23:06:00 2011-10-09 23:13:00 Open

    2 2011-10-09 23:13:00 2011-10-09 23:13:00 Assigned (User)

    6 2011-10-09 23:13:00 2011-10-10 04:47:00 Waiting for approval (Reassigned)

    10 2011-10-10 04:47:00 2011-10-10 04:47:00 Open

    11 2011-10-10 04:47:00 2011-10-10 05:00:00 Waiting for approval (Reassigned)

    22 2011-10-11 04:40:00 2011-10-11 04:40:00 Resolved

    Now, i need the difference between first row (start_time) and last row (end time)

  • Hi,

    select datediff(hh,(select top 1 start_time from mytable order by id asc),

    (select top 1 end_time from mytable order by id desc))

    Jeff.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply