date - SQL Datetime Avg -


i trying avg total days between 2 dates using sql.

my table follows

intsalesperson dtmdatesetup         dtmwelcomelettersent 1              2015-02-18 22:47:13.890  2015-03-19 19:53:04.153 1              2015-03-06 13:04:20.730  2015-03-19 19:55:29.800 1              2015-03-16 18:16:43.290  2015-03-19 19:55:25.690 

my sql query this?

select avg([dtmdatesetup] - [dtmwelcomelettersent]) avg_days [tblcustomer] [intsalespersonid] = 1 , [dtmwelcomelettersent] not null  

result should

avg_days 15 

thanks.

first calculate days between each date (i'm assuming sql server):

select [dtmdatesetup], [dtmwelcomelettersent],    datediff(day,dtmdatesetup,dtmwelcomelettersent) [tblcustomer] [intsalespersonid] = 1 , [dtmwelcomelettersent] not null 

then average easy:

select avg(datediff(day,dtmdatesetup,dtmwelcomelettersent)) [tblcustomer] [intsalespersonid] = 1 , [dtmwelcomelettersent] not null 

Comments

Popular posts from this blog

javascript - three.js lot of meshes optimization -

smartface.io - Proper way to change color scheme for whole application -

Email notification in google apps script -