【问题标题】:query with group by and count missing zero counts Google sheets使用 group by 查询并计算缺失的零计数 Google 表格
【发布时间】:2021-04-09 17:26:10
【问题描述】:

我可以得到列E 的计数(范围内没有空单元格)

=QUERY(Sheet1!D2:H,"select D, count(E) where F = 'person-person' group by D")

但如果我添加第二个where 子句

=QUERY(Sheet1!D2:H,"select D, count(E) where F = 'person-person' and H = 'Acquaintence' group by D")

我错过了我需要的零计数

感谢您对此的任何帮助

带有数据的 Google 表格 https://docs.google.com/spreadsheets/d/1p0gM4fHWjPf9k40h_GrJjqj8KrxSJDQ-E10LAOgS--Y/edit?usp=sharing

【问题讨论】:

  • 分享一份您的工作表副本(样本)以及所需结果的示例
  • 你所说的“零计数”是什么意思?
  • 我添加了一个带有示例的 Google 表格,很抱歉造成混淆

标签: google-sheets google-sheets-formula


【解决方案1】:

试试这个:

=ARRAYFORMULA(QUERY({Sheet1!D2:D,N(Sheet1!F2:F&Sheet1!H2:H="person-personAcquaintence")},"select Col1,SUM(Col2) where Col1'' group由 Col1"))

在查询中使用 SUM()'ing 可以让您以一种计数并不真正的方式显示 0。

【讨论】:

  • 谢谢你,马特,这基于你的方法=ARRAYFORMULA(QUERY({connections!D2:D,N(connections!H2:H="Acquaintence"), connections!F2:F},"select Col1,SUM(Col2) where Col1<>'' and Col3 ='person-person' group by Col1"))
  • Matt 你能解释一下这部分吗? ,N(connections!H2:H="Acquaintence") 谢谢
  • @xyz333 很高兴你在附近!连接!H2:H="acquaintence" 只生成一个 TRUE/FALSE 数组。 N() 将 TRUE/FALSE 值转换为 1 和 0,因此将 1 和 0 相加就像计数一样。
  • 这很好,我会记住的!再次感谢
猜你喜欢
  • 1970-01-01
  • 2011-09-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-18
  • 2012-03-29
  • 2022-01-15
相关资源
最近更新 更多