在 Google 表格中是否有嵌套查询调用的替代方法?

Is there an alternative to a nested query call in Google Sheets?

我已经写了这些查询,但我想我可能在 Google 表格中发现了一个错误:

=IFERROR(QUERY(QUERY({Sheet1!$A:$E},"select Col2, sum(Col4) where Col5 is null group by Col2 label sum(Col4) ''"), "Select Col1"))

另一个是一样的,不同的列:

=IFERROR(QUERY(QUERY({Sheet1!$A:$E},"select sum(Col4) where Col5 is null group by Col2 label sum(Col4) ''"), "Select Col1"))

删除 E 列中的 X 会显示 F:G 中的查询数据,但删除 X 会保留其中一个值。这里有一个live example

如果我移动列、删除 G 列或删除标签 hack,错误就会消失。

不幸的是,虽然这个例子看起来是做作的,但它来自一个更复杂的电子表格,我不能轻易修改它,所以我坚持使用 column/row 排列。

假设这是 Google 表格团队应该修复的错误(可能是由 label sum(Col4) '' 黑客引起的),还有其他方法可以解决这个问题吗?

根据 MattKing 和 player0 的建议进行编辑

这是未开具发票时的预期状态(参见 live example

然而,当我为所有项目开具发票时,会发生这种情况(有时,因为我注意到错误来来去去):

请注意,单元格 F7 中的值是 'p3' QUERY 剩余的文字。这不应该存在,这让我认为这是一个 Google 表格错误

where Col5 is null

您要求 query() 仅包含 E 列为空的行中的数据。所有数据行都在 E 列中包含一个值,因此结果将仅包括来自空白行的数据。也许你在追求 where Col5 is NOT null?

尝试:

=IFERROR(QUERY(QUERY({Sheet1!A2:E},
 "select Col2,sum(Col4) where Col5 is not null group by Col2"), 
 "offset 1", 0))

更新:

顶部的空行是包括空行的残留物。为了反驳你可以使用:

=IFERROR(QUERY(QUERY({Sheet1!$A:$E},
 "select Col2, sum(Col4) where Col5 is null and Col4 is not null group by Col2"), 
 "select Col1 offset 1", 0))

甚至:

=IFERROR(QUERY(QUERY({Sheet1!$A:$E},
 "select Col2, sum(Col4) where Col5 is null and Col4 is not null group by Col2 label sum(Col4)''"), 
 "select Col1", 0))

或更短:

=IFNA(INDEX(QUERY({Sheet1!A:E},
 "select Col2,sum(Col4) where Col5 is null and Col4 is not null group by Col2 label sum(Col4)''"),,1))

=IFNA(QUERY({Sheet1!A:E},
 "select sum(Col4) where Col5 is null and Col4 is not null group by Col2 label sum(Col4)''"))