select owner, sum(num_dogs), sum(num_cats) from (select owner, 1 as num_dogs, 0 as num_cats from dogs union select owner, 0 as num_dogs, 1 as num_cats from cats) group by owner
我更喜欢这个:
select owner , count(dog_name) dogs , count(cat_name) cats from cats FULL OUTER JOIN dogs ON (cats.owner = dogs.owner)