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