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
 General SQL Server Forums
 New to SQL Server Programming
 How to calculate average number of days taken

Author  Topic 

Maverick_
Posting Yak Master

107 Posts

Posted - 2014-01-16 : 07:15:19
Hi guys,

I am trying to figure out how to calculate the overall average number of days taken to complete something.

The two fields are enquiry_date (date enquiry is recorded) and complete_date (date enquiry completed/closed).

Each enquiry has a enquiry_number

Sample data typically looks like:

Enquiry number - enquiry_time - complete date
1 - 01/01/2014 - 12/01/2014
2 - 01/01/2014 - 11/01/2014
3 - 01/01/2014 - 10/01/2014
4 - 01/01/2014 - 07/01/2014
5 - 01/01/2014 - 12/01/2014
6 - 01/01/2014 - 04/01/2014

etc.

What is the piece of SQL which looks at the average date difference for each enquiry and then sums it all up to give an overall average number of days it takes?

I am a bit stuck!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-01-16 : 07:17:58
[code]
SELECT SUM(DATEDIFF(dd,enquiry_time,[complete date]))*1.0/NULLIF(COUNT([Enquiry number]),0) AS AverageEnquiryTime
FROM Table
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

Maverick_
Posting Yak Master

107 Posts

Posted - 2014-01-16 : 10:00:41
Thanks Visakh!
Go to Top of Page
   

- Advertisement -