查询完成,输出为空

Query completed with an empty output

https://docs.google.com/spreadsheets/d/1033hNIUutMjjdwiZZ40u59Q8DvxBXYr7pcWyRRHAdXk

这是一个 link 文件,它在其中不起作用!如果打开它,请转到名为 "My query stinks" 的 sheet。

名为 deposits 的 sheet 在 A 列(日期)、B 列(描述)和 C 列(金额)中有这样的数据:

+---+-----------+-----------------+---------+
|   |     A     |        B        |    C    |
+---+-----------+-----------------+---------+
| 1 | 6/29/2016 |      1000000044 |     480 |
| 2 | 6/24/2016 |      1000000045 |  359.61 |
| 3 | 8/8/2016  | 201631212301237 |   11.11 |
+---+-----------+-----------------+---------+

sheet"My Query Stinks"在A列(支票号码)、B列(查询失败)和C列(金额)中有数据:

+---+-----------------+------+--------+
|   |        A        |  B   |   C    |
+---+-----------------+------+--------+
| 1 |      1000000044 | #N/A |    480 |
| 2 |      1000000045 | #N/A | 359.61 |
| 3 | 201631212301237 | #N/A |  11.11 |
+---+-----------------+------+--------+

在 My Query Stinks 的 B 列中,我想输入一个查询。这是我正在尝试的:

=query(Deposits!A:C,"select A where A =" &  A2) 

出于某种原因,它 returns“#N/A 错误查询已完成,输出为空。”我希望它找到 1000000044(C4 中的值)与存款上的 1000000044 和 return 日期相匹配。

尝试

=query(Deposits!A:C,"select A where B ='" &A2&"'")

说明

Deposit B 列中的 1000000044 sheet 和 My Query Stinks sheet 的 A 列中的值设置为文本(字符串)值,因此应将它们括在单引号中 (撇号)否则 QUERY 认为此值是数字或变量名。

试试这个:

=query(Deposits!A:C,"select A where B = '"&A2&"' LIMIT 1")

您需要 LIMIT 1,因为您在第二列中有多个相同值的存款。

此问题的另一种解决方案是将“=”替换为 'contains':

=query(Deposits!A:C,"select A where B contains '" &A2&"'")

很简单,但是这个错误让我费了半个上午的时间。