我有一个完美的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
我错过了什么?
答案 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