【问题标题】:Google sheets Query WHERE only returns first rowGoogle 表格查询 WHERE 仅返回第一行
【发布时间】:2019-09-05 06:37:16
【问题描述】:

我正在尝试从匹配两个条件的工作表中查询数据。但是,当数据中有超过 1 行与我的条件匹配时,查询仅返回第一个结果。如何确保它返回符合条件的所有行?

我尝试更改单引号和双引号、大写字母、更改数据格式但没有任何效果。

查询:

query(Raw!A1:J29041, "select B,C,D,E, sum(F) where B='"&sheet1!A2&"' and E='good source' and not C='2016' GROUP BY B,C,D,E")

数据示例:

Client     Year    Month    Source         Count
Client a    2019    July    other source    1
Client a    2019    July    good source     2
Client a    2019    July    bad source      22
Client a    2019    July    good source     63
Client a    2019    July    another source  1
Client a    2019    July    another source  8

此数据的所需输出:

Client      Year    Month   Source          sum
Client a    2019    July    other source    65

【问题讨论】:

    标签: google-sheets google-sheets-formula google-sheets-query google-query-language


    【解决方案1】:

    数字不应该用单引号括起来

    尝试:

    =QUERY(Raw!A1:J29041, 
     "select B,C,D,E,sum(F) 
      where B="&sheet1!A2&" 
        and E='good source' 
        and not C='2016' 
      group by B,C,D,E", 1)
    

    或:

    =QUERY(Raw!A1:J29041, 
     "select B,C,D,E,sum(F) 
      where B="&sheet1!A2&" 
        and E='good source' 
        and not C=2016 
      group by B,C,D,E", 1)
    

    【讨论】:

    • 这给了我一个#VALUE 错误('unable to parse'),特别是将 '"&sheet1!A2&"' 更改为 "&sheet1!A2&"
    • 我确实找到了问题所在。在我的真实数据集中,where 子句中的 E 列位于我从中获取 SUM 的列之后。当我切换列顺序时它起作用(不知道为什么)。 – Laila Van Ments 2 分钟前 编辑删除
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-20
    • 2021-10-01
    • 2012-08-04
    • 1970-01-01
    相关资源
    最近更新 更多