我想请求您的帮助,为什么我会收到此错误: “不支持 JOIN 表达式”
代码:
SELECT
t2.KPICode1 AS OrigCode,
t0.KPITask AS OrigTask,
t2.ID AS TimID,
t2.Score AS OrigScore,
t3.ID AS AccID,
t3.Score AS DepScore,
t1.KPICode AS DepCode,
t1.KPITask AS DepTask,
IIF(ISNULL(t4.RevCount), 0, t4.RevCount) AS RevCount
FROM
(((KPI_qryMain AS t0
LEFT JOIN KPI_qryMain AS t1 ON t1.KPICode = t0.ChildKPICode)
LEFT JOIN KPI AS t2 ON t2.KPICode = t0.KPICode)
LEFT JOIN KPI AS t3 ON t3.KPICode = t0.ChildKPICode AND t3.UserID = t2.UserID)
LEFT JOIN
(SELECT COUNT(*) AS RevCount, RefNum
FROM KPI_tblLogs
WHERE Title = 'Daily Task'
AND LogDetails LIKE '%For revision%'
GROUP BY RefNum) AS t4 ON t4.RefNum = CSTR(t2.ID)
WHERE
t2.DueDate = #8/12/2024 6:00:00 PM#
AND t3.DueDate = #8/12/2024 6:00:00 PM#
AND t0.KPICode = 'SRSMRT03'
AND t2.UserID = 'XXX000165'
t0、t2 和 t3 之间有“不明确的连接”。
您可以将除 t3 之外的部分转换为子查询,然后
LEFT JOIN
将其转换为 T3,如下所示(当然不是唯一的方法):
SELECT
T0124.OrigCode
, T0124.OrigTask
, T0124.TimID
, T0124.OrigScore
, T3.ID as AccID
, T3.Score as DepScore
, T0124.DepCode
, T0124.DepTask
, T0124.RevCount
FROM
(
SELECT
t2.KPICode AS OrigCode
, t0.KPITask AS OrigTask
, t2.ID AS TimID
, t2.Score AS OrigScore
, t1.KPICode AS DepCode
, t1.KPITask AS DepTask
, IIf(t4.RevCount is null,0,t4.RevCount) AS RevCount
, t2.UserID as t2_UserID
, t0.ChildKPICode as t0_ChildKPICode
FROM
(((KPI_qryMain AS t0
INNER JOIN KPI AS t2
ON t0.KPICode = t2.KPICode)
LEFT JOIN KPI_qryMain AS t1
ON t0.ChildKPICode = t1.KPICode)
LEFT JOIN (SELECT COUNT(*) AS RevCount, RefNum
FROM KPI_tblLogs
WHERE Title = 'Daily Task'
AND LogDetails LIKE '*For revision*'
GROUP BY RefNum) AS t4
ON cstr(t2.ID) = t4.RefNum)
WHERE t2.DueDate="#12/08/2024 6:00:00 PM#"
AND t0.KPICode='xxxxx'
AND t2.UserID='yyyyyyy'
) AS T0124
LEFT JOIN KPI AS t3
ON (t2_UserID = t3.UserID AND T0124.t0_ChildKPICode = t3.KPICode)
我将你的通配符更改为
*
,因为这是针对MsAccess 和DAO 的;但如果您要从 ADO 调用此函数,则可以将它们改回 %
。
我还将 t0 和 t2 之间的
LEFT JOIN
更改为 INNER JOIN
,因为对于 t2 LEFT 连接的 WHERE
子句的标准不会有任何差异。