MS-Access SQL错误(使用聚合函数更新内部联接)

时间:2014-01-15 07:20:53

标签: sql ms-access ms-access-2010

我有一个完美的SELECT查询:

SELECT T1.Account, T1.Total, T2.Account, T2.Total
FROM tSummary2 as T1

INNER JOIN
(SELECT tSummary2.Account, 
Count(FinalData.ID) AS Total
FROM tSummary2 
INNER JOIN FinalData 
ON tSummary2.Account = FinalData.Account
GROUP BY tSummary2.Account) as T2

ON T2.Account = T1.Account

我需要做T1.Total = T2.Total。 但是每次尝试将其转换为更新查询都会失败并出现“SYNTAX ERROR(缺少运算符)。

以下是我的尝试:

UPDATE T1
SET T1.Total = T2.Total
FROM tSummary2 as T1

INNER JOIN
(SELECT tSummary2.Account, 
Count(FinalData.ID) AS Total
FROM tSummary2 
INNER JOIN FinalData 
ON tSummary2.Account = FinalData.Account
GROUP BY tSummary2.Account) as T2

ON T2.Account = T1.Account

我错过了什么?

1 个答案:

答案 0 :(得分:0)

您似乎错过了SELECT条款。

UPDATE T1
SET T1.Total = (SELECT T2.Total
                 FROM tSummary2 as T1
           INNER JOIN
                 (SELECT tSummary2.Account, 
                         Count(FinalData.ID) AS Total
                    FROM tSummary2 
              INNER JOIN FinalData 
                     ON tSummary2.Account = FinalData.Account
               GROUP BY tSummary2.Account) as T2
                     ON T2.Account = T1.Account)

我刚在T2.Total

之前添加了SELECT