给定以下示例查询,其中 Col A 是日期,Col B 是数字:
=QUERY(Sheet1!A:C, "SELECT A, SUM(B) WHERE (C = 'Www' OR C = 'ccC') GROUP BY A",1)
即使 SUM(B) = NULL,您如何让结果显示下一个 GROUP BY A,并让 NULL 显示 0,就像 ISNULL 一样。在T-SQL中,有一种方法可以做到这一点,但它不适用于Google。有人知道吗?
期望的结果:
<table border="1" style="width:20%">
<tr>
<td>1/1/02</td>
<td>5</td>
</tr>
<tr>
<td>1/2/02</td>
<td>0</td>
</tr>
<tr>
<td>1/3/02</td>
<td>5</td>
</tr>
<tr>
<td>1/4/02</td>
<td>10</td>
</tr>
<tr>
<td>1/5/02</td>
<td>0</td>
</tr>
</table>
Chris Hick 的回答
=QUERY({Sheet1!A:A,ARRAYFORMULA(IF((Sheet1!C:C="Www")+(Sheet1!C:C="ccC"),Sheet1!B:B,0)),Sheet1!C:C}, "SELECT Col1, SUM(Col2) WHERE Col1 is not null GROUP BY Col1",1)