我有 2 个 MySQL,我正在尝试获取每个城市至少拥有一只狗的所有者数量。我的桌子是:
owners
id, name, city
和
dogs
id, owner_id, name, weight
到目前为止,我有以下内容:
SELECT owners.city, count(dogs.id) AS 'Owners'
FROM owners INNER JOIN dogs ON (owners.id = dogs.owner_id)
GROUP BY owners.city
但是,这给了我每个城市的狗总数。但我想知道每个城市的狗主人数量。
我该怎么做?