我正在使用MS Access,尝试将3个表连接在一起。但是我得到了消息"加入表达不支持。"。 基本上我想加入两个表,分别是A_01HWeekEHCalendar和A00_Plant。 A00_Plant需要3列加入; Plant_Product,Plant_Code和Plant_Name。 Plant_Product,Plant_Code没问题,但是没有匹配Plant_Product的列。所以我必须添加A_ProductGroup 我不确定是否可以在一个查询中完成,或者我的SYNTAX是否出现错误。或者如果没有单独的查询,还有另一种方法可以做到这一点。 我还添加了我想要的图片并尝试运行并获得错误。
感谢。
SELECT
A_01HWeekEHCalendar.RunNo_H,
A_01HWeekEHCalendar.Audit_Week,
A_01HWeekEHCalendar.CurrentYear,
A_01HWeekEHCalendar.CurrentWeek,
A_01HWeekEHCalendar.TTSMonth,
A_01HWeekEHCalendar.Audit_Plant,
A_01HWeekEHCalendar.Audit_plantname,
A_01HWeekEHCalendar.Audit_Qacode,
A_01HWeekEHCalendar.Audit_Qaname,
A_01HWeekEHCalendar.Audit_Product,
A00_Plant.HCA_StartDate
FROM
(A_01HWeekEHCalendar LEFT JOIN A_ProductGroup
ON A_01HWeekEHCalendar.Audit_Product = A_ProductGroup.R_Code)
LEFT JOIN A00_Plant
ON A_01HWeekEHCalendar.Audit_plantname = A00_Plant.Plant_Name
AND A_01HWeekEHCalendar.Audit_Plant = A00_Plant.Plant_Code
AND A_ProductGroup.R_Code = A00_Plant.Plant_Product;
答案 0 :(得分:1)
你很幸运,因为你只想要一列。您可以使用相关子查询解决此问题:
SELECT . . .,
(SELECT TOP (1) A00_Plant.HCA_StartDate
FROM A00_Plant
WHERE A_01HWeekEHCalendar.Audit_plantname = A00_Plant.Plant_Name
AND
A_01HWeekEHCalendar.Audit_Plant = A00_Plant.Plant_Code AND
A_ProductGroup.R_Code = A00_Plant.Plant_Product
) as HCA_StartDate
FROM A_01HWeekEHCalendar LEFT JOIN
A_ProductGroup
ON A_01HWeekEHCalendar.Audit_Product = A_ProductGroup.R_Code ;