Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Average Time Difference

Author  Topic 

Pryach
Starting Member

3 Posts

Posted - 2011-01-19 : 12:09:35
I have a table that looks like this:


id profileid action datetime
1 524123 STARTED 01/19/2011 08:00:00
2 524123 FINISHED 01/19/2011 08:30:00
3 182901 STARTED 01/19/2011 09:00:00
4 182901 FINISHED 01/19/2011 09:15:00
5 819102 STARTED 01/19/2011 09:30:00
6 819102 FINISHED 01/19/2011 10:00:00
7 284102 STARTED 01/19/2011 10:05:00


I want to find out what the average time is to go from Started to Finished. We have three people being finished, thirty minutes, fifteen minutes, and thirty minutes. So the average time is 25 minutes (although I'd like the results in seconds, 1500).

I'm pretty new to SQL so if someone could help me out I would appreciate it. I'm sure I'm going to have to use DATEDIFF and AVG, I'm just not sure how to get the start and end dates in there.

Thanks!

michael.appleton
Posting Yak Master

160 Posts

Posted - 2011-01-19 : 12:29:25
You'll have to do a self join on profileid, then use datediff, then just do avg function
Go to Top of Page
   

- Advertisement -