【问题标题】:Google Sheets Query Language, return 0谷歌表格查询语言,返回 0
【发布时间】:2016-09-23 09:20:18
【问题描述】:

当找不到查询的数据时,让查询函数返回 0 时遇到了麻烦。

鉴于以下数据...

由于每张纸都是不同的玩家,我需要计算每人玩的游戏数量以及这些游戏的结果。

有些玩家可能彼此在同一个游戏中,因此游戏 ID 作为唯一标识符提供,因此这些游戏只计算一次,这部分我正在工作。

我现在要做的是记录 A 队在每个房间的获胜次数。

你可以在上面的截图中看到我的问题。

Here is the sample sheet有以上数据。

这是用于最右侧示例的公式

=QUERY({QUERY(UNIQUE(QUERY({Sheet1!A2:C;Sheet2!A2:C;Sheet3!A2:C},"select Col1, Col2 where Col2 <> '' and Col3 contains 'A'")),"select Col1, 1");QUERY(QUERY({Sheet1!A2:C;Sheet2!A2:C;Sheet3!A2:C},"select Col1, Col2 where Col2 = '' and Col1 <> '' and Col3 contains 'A'"),"select Col1, 1")},"select Col1, sum(Col2) where Col1 <> '' group by Col1 label sum(Col2) 'TeamA Wins', Col1 'Room'")

有人可以帮忙吗?

【问题讨论】:

    标签: google-sheets google-query-language


    【解决方案1】:

    您可以在公式中添加虚拟数据:

    =QUERY(data;{QUERY(UNIQUE(QUERY({Sheet1!A2:C;Sheet2!A2:C;Sheet3!A2:C},"select Col1, Col2 where Col2 <> '' and Col3 contains 'A'")),"select Col1, 1");QUERY(QUERY({Sheet1!A2:C;Sheet2!A2:C;Sheet3!A2:C},"select Col1, Col2 where Col2 = '' and Col1 <> '' and Col3 contains 'A'"),"select Col1, 1")},"select Col1, sum(Col2) where Col1 <> '' group by Col1 label sum(Col2) 'TeamA Wins', Col1 'Room'")
           ^^^^
    

    数据是一个命名范围,它看起来像这样:

    制作:

    1. 将数据粘贴到单独的工作表中,如上图所示。
    2. 选择范围A1:B6
    3. 转到Data → Named range → 称其为“数据”
    4. 输入公式,它现在应该可以正常工作了。

    Sample file 带有工作公式

    【讨论】:

    • 我添加了示例文件
    • 有效!再次感谢 Max :)
    • 如果你还在的话,现在房间是按字母顺序排列的,有没有办法让它们以与命名范围相同的顺序显示?
    • 您可以按正确的顺序使用房间列表,在其他地方使用您当前的公式计算总和,然后将vlookuparrayformula stackoverflow.com/a/29901603/5372400
    猜你喜欢
    • 2021-07-09
    • 1970-01-01
    • 1970-01-01
    • 2018-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-18
    • 1970-01-01
    相关资源
    最近更新 更多