Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
If statement 对googlesheets中连接数组的查询_If Statement_Google Sheets_Google Sheets Formula_Array Formulas_Google Sheets Query - Fatal编程技术网

If statement 对googlesheets中连接数组的查询

If statement 对googlesheets中连接数组的查询,if-statement,google-sheets,google-sheets-formula,array-formulas,google-sheets-query,If Statement,Google Sheets,Google Sheets Formula,Array Formulas,Google Sheets Query,我正在尝试对几个范围运行аquery,这些范围与{}类似query({A2:C5,if(C1:C5='something',1,0)},“select…”。但是我得到了一个裁判!消息函数数组\u行参数2的行大小不匹配时出错。预期:4。实际情况:1。原因是什么 下面是一个详细的例子。假设我有一张这样的桌子: id kind color 1 a green 2 a green 3 b green 4 c blue 我想得到一个表格,显示每种类型的绿色单元格数

我正在尝试对几个范围运行аquery,这些范围与{}类似
query({A2:C5,if(C1:C5='something',1,0)},“select…”
。但是我得到了一个裁判!消息
函数数组\u行参数2的行大小不匹配时出错。预期:4。实际情况:1。
原因是什么

下面是一个详细的例子。假设我有一张这样的桌子:

id  kind    color
1   a   green
2   a   green
3   b   green
4   c   blue
我想得到一个表格,显示每种类型的绿色单元格数量:

kind    color_count
a   2
b   1
c   0
最初,我尝试使用where子句进行查询:

=query(A2:C5, "select B, count(C) where C='green' group by B", -1)
但这不包括具有零值的行。因此,我尝试添加一个额外的列,其中绿色值为1,其他值为0,并在没有where子句的情况下使用SUM:

=query({A2:C5, if(C2:C5="green", 1, 0)}, "select B, sum(D) group by B", -1)
但这给了上面$REF

作为一种解决方法,我在表中添加了一列D,其中包含公式

=arrayformula(if(C2:C5="green", 1, 0))
然后,以下查询工作并给出所需的结果:

=query(A2:D5, "select B, sum(D) group by B", -1)

但是有可能避免这个人工列吗?

如果
只返回1个单元格,除非您使用
数组公式。因此,错误是在一个点上的,因为一侧有4个单元格,另一侧有1个单元格

尝试:


I trued=arrayformula(查询({A2:C5,if(C2:C5=“green”,1,0)},“选择B,按B对(D)组求和”,-1))。但这是有价值的!错误:无法分析函数查询参数2的查询字符串:否列:B。第二个建议给出了错误的答案。最后一行应该是c0i,我意识到我必须使用Col1、Col2,而不是A、B等作为列名。然后事情就开始了。谢谢
=ARRAYFORMULA(QUERY({B:B, IF(C:C="green", 1, 0)}, 
 "select Col1,sum(Col2) 
  where Col1 is not null 
  group by Col1 
  label sum(Col2)''", 0))