我实际上是第一次尝试使用一堆嵌套的vlookup在excel中执行此操作并遇到相同的错误,所以我尝试在访问中进行思考我会解决问题,但我得到完全相同的问题。
我想要做的就是通过一个内联接连接两个表,一个表中有一列,另一个表中有多个列之一(我希望输出是(导致我的问题的那个)这是一个小数据样本和我试图得到的查询。
表1:
Search unique
gloves 5000
beaker 3000
tea 1000
timer 2000
表2:
Name Field1 Field 2 Field3 ....
gloves hello goodbye
Time timer clock
hi tea
当我进行内部联接时,我得到:
gloves 5000
而不是得到:
gloves 5000
tea 1000
timer 2000
因此它只在第一栏加入,不知道为什么?这是我在Access中写的查询:
SELECT DISTINCT Product.Category, Analytics.Unique
FROM Product INNER JOIN Analytics ON IIF(Analytics.Search = Product.Category
Is Not Null,Analytics.Search = Product.Category, IIF(Analytics.Search =
Product.Field4 Is Not Null, Analytics.Search = Product.Field4,
IIF(Analytics.Search = Product.Field5 Is Not Null, Analytics.Search =
Product.Field5, IIF(Analytics.Search = Product.Field6 Is Not Null,
Analytics.Search = Product.Field6, IIF(Analytics.Search = Product.Field7 Is
Not Null, Analytics.Search = Product.Field7, IIF(Analytics.Search =
Product.Field8 Is Not Null, Analytics.Search = Product.Field8,
IIF(Analytics.Search = Product.Field9 Is Not Null, Analytics.Search =
Product.Field9, IIF(Analytics.Search = Product.Field10 Is Not Null,
Analytics.Search = Product.Field10))))))));
答案 0 :(得分:1)
我相信你的表达不会测试你认为他们正在测试的内容。部分表达
Analytics.Search = Product.Category Is Not Null
相当于
(Analytics.Search = Product.Category) Is Not Null
换句话说,测试布尔值是否不为空。并且布尔值永远不会为空。
你可能想要更像这样的东西:
... ON Analytics.Search = IIF(Product.Category Is Not Null, Product.Category,
IIF(Product.Field4 Is Not Null, Product.Field4, ...
答案 1 :(得分:0)
select table2.search, table1.unique
from table1 t
inner join table2 t2 on t2.name = t.search
inner join table2 t3 on t3.field1 = t.search
inner join table2 t4 on t4.field2 = t.search
inner join table2 t5 on t5.field3 = t.search