select a.a, aa.aa, b.b, a.t1, a.t2, a.t3, a.t4
from (select count(1) a, t1, t2, t3, t4 from A group by t1, t2, t3, t4) a
left join (select count(1) aa, t1, t2, t3, t4
from A where t4 = 'success' group by t1, t2, t3, t4) aa
on a.t1 = aa.t1
and a.t2 = aa.t2
and a.t3 = aa.t3
and a.t4 = aa.t4
left join (select count(1) b, t1, t2, t3, t4
from B group by t1, t2, t3, t4) b
on b.t1 = aa.t1
and b.t2 = aa.t2
and b.t3 = aa.t3
and b.t4 = aa.t4