请检查我的聚合函数的sql代码以更新访问中的表

时间:2016-12-15 00:28:39

标签: sql ms-access

我在运行此sql以进行访问中的聚合更新时遇到问题。我想要做的是更新表[员工数据库]中的“pointbalance”,将表2中“nbrpoint”的总和替换为“SysID”。它会返回一条错误消息,如下面的“查询表达式中的语法错误(缺少运算符)。我被困在这半天,有人能告诉我我的sql编码有什么问题吗?我们走了:

Update [employee database] 
Set [pointbalance] =[pointbalance] - t2.nbrpointsum
From [employee database]
Inner join (select [sys ID],[entered],sum(nbrpoint) as nbrpointsum 
            from [temp call log entries]
            group by [Sys ID]) as t2
On t2.[sys ID] = [employee database].[SysID]

提前谢谢!!!

1 个答案:

答案 0 :(得分:0)

MS Access具有不同的UPDATE查询语法。语法遵循以下顺序:

UPDATE <table1>
INNER JOIN <table2>
ON <some conditions>
SET <update expression>;

它与你的不同(BTW是外观上的MS SQL语法)

您需要重新编写查询:

Update [employee database] 
Inner join (select [sys ID],[entered],sum(nbrpoint) as nbrpointsum 
            from [temp call log entries]
            group by [Sys ID]) as t2
On t2.[sys ID] = [employee database].[SysID] 
Set [employee database].[pointbalance] = [employee database].[pointbalance] - t2.nbrpointsum