首页 > 解决方案 > 使用 Google 表格查询功能进行字符串比较

问题描述

我无法理解为什么我的查询不起作用。结果始终为空,除非删除 C=D 然后我得到一个 ID 列表。该公式将用于名为 IDS 的新工作表,并从 Threads 中提取数据。我的查询是:

=QUERY(Threads!A:D,"select A where B='No Label'and C=D",-1)

我试图查询的表看起来像这样:

|    IDS (A)     |Labels(B) |Email List(C)      | Matching Emails(D)|
|----------------|----------|-------------------|-------------------|
|179cd3g671269f69|No Label  |pat@rus.com        |bro@rus.com        |
|179cd83p7a655449|No Label  |SCP.admi@pab.com   |mike@rus.com       |
|179cb58p79236216|No Label  |SCP.admi@pab.com   |pat@rus.com        |
|179c9er26ca777c8|No Label  |dar@rus.com        |sed@rus.com        |
|179c8l3c5b46e4ga|No Label  |dar@rus.com        |will@rus.com       |
|179c8oe73a13d487|No Label  |pat@rus.com        |dar@rus.com        |

标签: google-sheetsgoogle-sheets-formula

解决方案


它不起作用,因为当 Col C 中的值与 Col D 相同时没有行。

如果要检查 Col C 中的每一行与 Col D 中的任何值,请使用:

=QUERY(Threads!A:D,"select A where B='No Label' and C matches '"&textjoin("|",true,D2:D)&"' ",1)

textjoin("|",true,D2:D)带回 Col D 中的所有值:

bro@rus.com|mike@rus.com|pat@rus.com|sed@rus.com|will@rus.com|dar@rus.com|pat@rus.com

|分隔符的作用是OR,所以bro@rus.com OR mike@rus.com...

如果需要,如果将来出现重复项,您可以带回一个唯一列表:

textjoin("|",true,unique(D2:D))

所以公式是:

=QUERY(Threads!A:D,"select A where B='No Label' and C matches '"&textjoin("|",true,unique(D2:D))&"' ",1)

反过来进行检查(Col D 匹配 Col C):

=QUERY(Threads!A:D,"select A where B='No Label' and D matches '"&textjoin("|",true,unique(C2:C))&"' ",1)


推荐阅读