(Google Sheets) How can I reference a cell value (string) in the 2nd parameter of the query function?

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

(Google Sheets) How can I reference a cell value (string) in the 2nd parameter of the query function?

问题

假设我在单元格A2中有一个字符串值为"name"。

我想要使用QUERY函数以这样的方式引用第二个参数中单元格的值:

=QUERY(Sheet1!A:E, "select Col4 where Col3 = 'A2' ", 0)

但是,显然这样是行不通的,因为由于参数位于''之内,函数会将其作为字符串读取(而不是作为name)。

我该如何引用单元格本身,以便它读取单元格的值而不是'A2'?

英文:

Imagine I have a string value at cell A2 = "name".

I want to use query in such a way that I can reference the value of the cell in the second parameter like this:

=QUERY(Sheet1!A:E, "select Col4 where Col3 = 'A2' ", 0)

But of course, that won't work because since the parameter is inside '', the function reads it as a string (as A2 instead of name).

How can I reference the cell itself so that it will read the value of the cell instead of 'A2'?

答案1

得分: 2

<!-- language-all: js -->

你可以尝试以下代码:

=QUERY({Sheet1!A:E}, "select Col4 where Col3 = '"&A2&"' ", 0)

或者

=QUERY(Sheet1!A:E, "select D where C = '"&A2&"' ", 0)

或者

=filter(Sheet1!D:D,Sheet1!C:C=A2)
英文:

<!-- language-all: js -->

You may try:

=QUERY({Sheet1!A:E}, &quot;select Col4 where Col3 = &#39;&quot;&amp;A2&amp;&quot;&#39; &quot;, 0)

OR

=QUERY(Sheet1!A:E, &quot;select D where C = &#39;&quot;&amp;A2&amp;&quot;&#39; &quot;, 0)

OR

=filter(Sheet1!D:D,Sheet1!C:C=A2)

huangapple
  • 本文由 发表于 2023年8月9日 14:20:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76865068.html
匿名

发表评论

匿名网友

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

确定