如何使该查询采用多列?

时间:2019-06-20 04:55:35

标签: regex filter google-sheets google-sheets-formula google-sheets-query

我有这个查询:

=QUERY(Sheet1!A:Z, "Select * Where B contains 'name")

我想确定在B的位置,多列,例如A,B,C。

2 个答案:

答案 0 :(得分:2)

为澄清起见,您想搜索的不仅仅是“名称”列B吗?您是否还想查看它是否在D,H,Z等列中?

如果是这样:

=QUERY(Sheet1!A:Z,"SELECT * WHERE (A CONTAINS 'name' OR B CONTAINS 'name' OR C CONTAINS 'name')")

为要检查的每一列添加OR column CONTAINS 'name'

例如

this screenshot

显示它检查A,B和C列中的“名称”,但不检查D列。

答案 1 :(得分:0)

较短的版本是这样的:

=QUERY(Sheet1!A:Z, "where A contains 'name' 
                       or B contains 'name' 
                       or C contains 'name')", 0)

如果您的数据集确实非常庞大,则可能要使用FILTER而不是查询:

=FILTER(Sheet1!A:Z, REGEXMATCH(Sheet1!A:A, "name")+
                    REGEXMATCH(Sheet1!B:B, "name")+
                    REGEXMATCH(Sheet1!C:C, "name"))

或类似:

=FILTER(Sheet1!A:Z, ISNUMBER(SEARCH("*name*", Sheet1!A:A))+
                    ISNUMBER(SEARCH("*name*", Sheet1!B:B))+
                    ISNUMBER(SEARCH("*name*", Sheet1!C:C)))