我有一个问题:我在Access中有3个表 -
Assignments (Date, Parent Company ID, Sales Rep ID)
Roster (Date, Sales Rep ID, Team ID)
Goals (Date, Team ID)
首先,我离开了加入Roster
的作业以获得最终的Roster
表格,我试图在Goals
上加入这个新表格,但我收到的错误是:< / p>
Specified field FR.date could refer to more than one table listed in the from clause of your SQL statement.
下面是SQL:
SELECT *
from Goals as G
LEFT JOIN
(SELECT *
FROM Assignments AS A
LEFT JOIN Roster AS R
ON (A.[Sales Rep ID] = R.[User ID])
AND (A.Date = R.Date)
) FR
on (G.Date = FR.Date)
AND G.[Team ID] = FR.[Team ID]
我在这里做错了什么?
答案 0 :(得分:1)
此查询
SELECT *
FROM Assignments AS A
LEFT JOIN Roster AS R
ON (A.[Sales Rep ID] = R.[User ID])
AND (A.Date = R.Date)
包含2个具有相同字段名称的列,在本例中为日期,当您编写G.Date = FR.Date时,您对字段日期的含糊不清的引用表A或R
答案 1 :(得分:0)
虽然MS Access在FROM
子句中需要额外的括号,但您不需要这样的子查询:
SELECT *
FROM (Goals as G LEFT JOIN
Assignments AS A
ON G.Date = A.Date AND G.[Team ID] = A.[Team ID]
) LEFT JOIN
Roster as R
ON A.[Sales Rep ID] = R.[User ID] AND A.Date = R.Date;
目前还不清楚[Team ID]
来自何处,因此您可能需要将该条件放在第二个ON
子句中。