如何将 COUNTIF 与 OR 结合使用
问题描述:
在 Google 电子表格中,我需要在具有多个条件的范围内使用 COUNTIF
函数.所以在下表中,我需要像 =COUNTIF(B:B,"Mammal"or"Bird")
之类的东西,并返回 4 的值.
In Google Spreadsheets, I need to use the COUNTIF
function on a range with multiple criteria. So in the table below, I would need to have something like =COUNTIF(B:B,"Mammal"or"Bird")
and return a value of 4.
A |B
-------------------
Animal | Type
-------------------
Dog | Mammal
Cat | Mammal
Lizard | Reptile
Snake | Reptile
Alligator | Reptile
Dove | Bird
Chicken | Bird
我尝试了很多不同的方法,但都没有成功.
I've tried a lot of different approaches with no luck.
答
一个选项:
=COUNTIF(B:B; "Mammal") + COUNTIF(B:B; "Bird")
根据文档:
注意事项
COUNTIF 只能使用单一条件执行条件计数.要使用多个条件,请使用 COUNTIFS 或数据库函数DCOUNT 或 DCOUNTA.
COUNTIF can only perform conditional counts with a single criterion. To use multiple criteria, use COUNTIFS or the database functions DCOUNT or DCOUNTA.
COUNTIFS
:此功能仅在 新的 Google 表格.
示例:
=DCOUNTA(B:B; 2; {"Type"; "Mammal"; "Bird"})