在Google Sheets中,使用”and”连接的QUERY函数中的多个列。

huangapple go评论51阅读模式
英文:

Multiple columns in QUERY with "and" in Google Sheets

问题

Here is the translation of the provided content:

如何在查询中选择2列而不是1列来搜索指定的值?当前的公式只搜索Col4,我需要在屏幕1上的突出显示的位置搜索Col4和Col5

为了清晰起见,让我们来看一下“Data”工作表的截图2。在当前的公式中,输出只针对第4列(屏幕上的红色)是的,但如何使输出同时针对第4列和第5列(屏幕上的蓝色)呢?我尝试了不同的选项,包括插入“或”,但没有成功。

截图1
在Google Sheets中,使用”and”连接的QUERY函数中的多个列。

截图2
在Google Sheets中,使用”and”连接的QUERY函数中的多个列。

A7单元格中的公式:

=QUERY({Data!A2:E}," where (Col4='"& B1&"' or Col5='"& B1&"') "&IFS(
    C3,"and Col2='"& B3&"'"&IF( C2,"and Col4='"& B2&"'"",)&"",
    E3,"and Col2='"& D3&"'"&"",
    C2,"and Col4='"& B2&"'"",
    NOT(AND(E3,C3)),"  "&IF( C2,"and Col4='"& B2&"'"",)&"")&"")
英文:

How to choose 2 columns in QUERY instead of one to search for specified values? The current formula searches only one Col4, I need to search both Col4 and Col5 in the highlighted places on the screen 1.

For clarity, let's take a screenshot 2 of the "Data" sheet. In the current formula, the output is only for column 4 (red colour on screen), but how do I make the output for both column 4 and column 5 (blue colour on screen)? I tried different options, including inserting "or", but it didn't work

Screenshot 1
在Google Sheets中,使用”and”连接的QUERY函数中的多个列。

Screenshot 2
在Google Sheets中,使用”and”连接的QUERY函数中的多个列。

Formula in A7:

=QUERY({Data!A2:E}," where (Col4='"& B1&"' or Col5='"& B1&"') "&IFS(
C3,"and Col2='"& B3&"'"&IF( C2,"and Col4='"& B2&"'",)&"",
E3,"and Col2='"& D3&"'",C2,"and Col4='"& B2&"'",
NOT(AND(E3,C3))," "      &IF( C2,"and Col4='"& B2&"'",)&"")&"")

答案1

得分: 1

=QUERY({Data!A2:E},"where (Col4='"& B1&"' or Col5='"& B1&"') "&IFS(
C3,"and Col2='"& B3&"'"&IF( C2,"and (Col4='"&B2&"' or Col5='"&B2&"')",)&"",
E3,"and Col2='"& D3&"'" C2,"and (Col4='"&B2&"' or Col5='"&B2&"')",
NOT(AND(E3,C3))," " &IF( C2,"and (Col4='"&B2&"' or Col5='"&B2&"')",)&"")

英文:

Answer:

=QUERY({Data!A2:E},"where (Col4='"& B1&"' or Col5='"& B1&"') "&IFS(
C3,"and Col2='"& B3&"'"&IF( C2,"and (Col4='"&B2&"' or Col5='"&B2&"')",)&"",
E3,"and Col2='"& D3&"'",      C2,"and (Col4='"&B2&"' or Col5='"&B2&"')",
NOT(AND(E3,C3))," "      &IF( C2,"and (Col4='"&B2&"' or Col5='"&B2&"')",)&"")&"")

huangapple
  • 本文由 发表于 2023年5月29日 23:51:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76358719.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定