AVG time spent on multiple rows SQL-server?
Posted
by seo20
on Stack Overflow
See other posts from Stack Overflow
or by seo20
Published on 2010-05-25T18:14:05Z
Indexed on
2010/05/25
18:21 UTC
Read the original article
Hit count: 295
I have a table tblSequence with 3 cols in MS SQL: ID, IP, [Timestamp]
Content could look like this:
ID IP [Timestamp]
--------------------------------------------------
4347 62.107.95.103 2010-05-24 09:27:50.470
4346 62.107.95.103 2010-05-24 09:27:45.547
4345 62.107.95.103 2010-05-24 09:27:36.940
4344 62.107.95.103 2010-05-24 09:27:29.347
4343 62.107.95.103 2010-05-24 09:27:12.080
ID is unique, there can be n number of IP's.
Would like to calculate the average time spent per IP. in a single row
Know you can do something like this:
SELECT CAST(AVG(CAST(MyTable.MyDateTimeFinish - MyTable.MyDateTimeStart AS float)) AS datetime)
But how on earth do I find the first and last entry of my unique IP row so I can have a start and finish time? I'M stuck.
Would like to calculate the average time spent per IP. in a single row
© Stack Overflow or respective owner