我想从包含动物类型字段中的多少只狗和猫的单个表中查找。
如何在单个查询中查找多个字段的计数?
你可以做这样的事情。我假设您的表名为“Animals”,而您所指的动物类型字段名为“AnimalType”。
SELECT AnimalType, COUNT(AnimalType)
FROM Animals
WHERE AnimalType IN ('Cats','Dogs')
GROUP BY AnimalType
select type, count(*) from the_table group by type;
或者如果你只想要猫和狗(但没有鸟):
select type, count(*) from the_table
where type in ('cat', 'dog')
group by type;