sql - Average difference between two datetime columns -
i want find average time each customer spent on form.
the table looks this:
customerid | intime | outtime
gives average duration in seconds - group id , use aggregate avg function
create table #test ( customerid int, intime datetime, outtime datetime ) insert #test values (1,'20140101 10:00','20140101 12:00'), (1,'20140102 10:00','20140102 12:00'), (2,'20140101 10:00','20140101 20:00'), (3,'20140103 10:00','20140103 11:00') select customerid, avg(datediff(ss,intime,outtime)) #test group customerid drop table #test
Comments
Post a Comment