If statement Google电子表格中每天字符串组的出现次数

If statement Google电子表格中每天字符串组的出现次数,if-statement,google-sheets,google-sheets-formula,array-formulas,google-sheets-query,If Statement,Google Sheets,Google Sheets Formula,Array Formulas,Google Sheets Query,我在谷歌电子表格中有如下表格数据: Date|Diet 4-Jan-2020|Coffee 4-Jan-2020|Snacks 4-Jan-2020|xyz 4-Jan-2020|Coffee 5-Jan-2020|Snacks 5-Jan-2020|abc 6-Jan-2020|Coffee 6-Jan-2020|Snacks Date | No of times I had Coffee 4-Jan-2020| 2 5-Jan-2020| 0 6-Jan-2020| 1 这张表是

我在谷歌电子表格中有如下表格数据:

Date|Diet
4-Jan-2020|Coffee
4-Jan-2020|Snacks
4-Jan-2020|xyz
4-Jan-2020|Coffee
5-Jan-2020|Snacks
5-Jan-2020|abc
6-Jan-2020|Coffee
6-Jan-2020|Snacks
Date | No of times I had Coffee    
4-Jan-2020| 2
5-Jan-2020| 0
6-Jan-2020| 1
这张表是我每天吃的食物清单。我想知道我每天喝咖啡的次数。所以我想得到如下输出:

Date|Diet
4-Jan-2020|Coffee
4-Jan-2020|Snacks
4-Jan-2020|xyz
4-Jan-2020|Coffee
5-Jan-2020|Snacks
5-Jan-2020|abc
6-Jan-2020|Coffee
6-Jan-2020|Snacks
Date | No of times I had Coffee    
4-Jan-2020| 2
5-Jan-2020| 0
6-Jan-2020| 1
我使用这个查询来获得输出

=query(A1:B1425,"select A, COUNT(B) where B='Coffee' group by A")
通过这个查询,我得到以下输出。请注意,我没有得到那些日子,当我没有喝咖啡

4-Jan-2020| 2
6-Jan-2020| 1
因此,2020年1月5日的计数缺失,因为那天没有“咖啡”字符串


如何获得所需的输出,包括计数0?谢谢。

您可能需要将计数器更改为If语句。 类似于“如果(计数(B)其中B='Coffee'组由A“>0,计数(B)其中B='Coffee'组由A“>0)。 这将强制计数器具有实际值(0),即使找不到任何值

请尝试:

=ARRAYFORMULA({UNIQUE(FILTER(A1:A, A1:A<>"")), 
  IFNA(VLOOKUP(UNIQUE(FILTER(A1:A, A1:A<>"")), 
 QUERY(A1:B, 
 "select A,count(B) 
  where B='Coffee' 
  group by A 
  label count(B)''"), 2, 0))*1})

我尝试了此操作,但没有成功。但是,用户“player0”提供的查询已解决。感谢您的回复。