简体   繁体   English

Google表格Query()函数返回意外数据

[英]Google Sheets Query() Function Returning Unexpected Data

I am having trouble with the QUERY() function in Google Sheets. 我在Google表格中使用QUERY()函数遇到麻烦。 I'm not certain I am using the correct function to generate the required data. 我不确定我使用的是正确的函数来生成所需的数据。 I am far more comfortable with T-SQL, but my wife needs a mailing list generated from her current google sheets. 我对T-SQL更加满意,但是我妻子需要从她当前的Google表格生成的邮件列表。

The facts: 事实:

  • Sheet2 is populated with data from B3:K150 用来自B3:K150的数据填充Sheet2

  • I have a list of names in Sheet2, Column B. 我在Sheet2的B列中有一个名称列表。

  • I have a list of addresses in Sheet2, Column G 我在Sheet2的G列中有一个地址列表

  • Sheet1 contains no data other than the data populated in Column B (See below) 除列B中填充的数据外,Sheet1不包含任何数据(请参见下文)

  • Sheet1, Column B is populated with a unique list of names from Sheet2, Column B using =Unique('Sheet2'!$B$3:$B$150). Sheet1的B列使用= Unique('Sheet2'!$ B $ 3:$ B $ 150)填充了Sheet2的B列的唯一名称列表。

Goal: 目标:

  • I would like to populate Sheet1, Column C with Sheet2, Column G WHERE Sheet1(ColumnB) = Sheet2(ColumnB) 我想用Sheet2,G 填充Sheet1,C 列,其中 Sheet1(ColumnB)= Sheet2(ColumnB)

Obviously, using SQL, we would write this as such: 显然,使用SQL,我们将这样编写:

SELECT [Sheet1].[ColumnB]
      ,[Sheet1].[ColumnC] 
FROM [Sheet1] 
    INNER JOIN [Sheet2] 
        ON [Sheet1].[ColumnB] = [Sheet2].[ColumnB]

What I have tried: 我尝试过的

INSERT the following formula into Sheet1!C3: 将以下公式插入Sheet1!C3:

=QUERY(Sheet2!B3:K150,"SELECT G WHERE B ='"&Sheet1!B3:B150&"'",0)

Sheet screenshots: 工作表屏幕截图:

在此处输入图片说明 在此处输入图片说明

What am I missing? 我想念什么?

This worked well for me: 这对我来说很好:

=unique(query(Sheet2!B3:G150,"select B,G"))

as posted by user: pnuts in comments above. 由用户发布: 以上评论中的pnuts

在Sheet1C3 =Arrayformula(if(B3:B=Sheet2!B3:B,Sheet2!G3:G,""))尝试此操作,请让我知道是否需要我解释该公式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM