如何将COUNTIF与OR结合

如何将COUNTIF与OR结合

问题描述:

在Google Spreadsheets中,我需要在具有多个条件的范围内使用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 :此功能仅在示例:

=DCOUNTA(B:B; 2; {"Type"; "Mammal"; "Bird"})