I think Alan and I had the same idea but he's just a little quicker on the keyboard. 🙂
select *
from
(
select tablename, avg(datediff(ms,starttime,endtime)) over (partition by tablename) averageMS from timetest
) source
group by tablename, averageMS