select A.a, count(*) from A inner join B on A.a = B.b group by a
union
select A.a, 0 from A where a not in (select distinct b from B)
order by a