select a.id,a.all-isnull(b.out,0) from A left join B on a.id=b.id