select id=isnull(a.id,b.id)
,name=isnull(a.name,b.name)
,type1,type1b,type2,type2b
,type3,type3b,type4,type4b
from(
select b.id,b.name
,type1=sum(case when b.type=1 then 1 else 0 end)
,type1b=sum(case when b.type=1 then a.dur else 0 end)
,type2=sum(case when b.type=2 then 1 else 0 end)
,type2b=sum(case when b.type=2 then a.dur else 0 end)
from A,B where a.name=b.name
group by b.id,b.name
)a full join(
select c.id,c.name
,type3=sum(case when b.type=3 then 1 else 0 end)
,type3b=sum(case when b.type=3 then a.dur else 0 end)
,type4=sum(case when b.type=4 then 1 else 0 end)
,type4b=sum(case when b.type=4 then a.dur else 0 end)
from A,C where a.name=c.name
group by c.id,c.name
)b on a.id=b.id and a.name=b.name