Google 查询,Return GroupBy 即使 Sum 为 0
Google Query, Return GroupBy even with Sum 0
给定以下示例查询,其中 A 列为日期,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>
=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)
给定以下示例查询,其中 A 列为日期,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>
=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)