使用 update 和 Aggregrate sum() 函数更新 MS Access 数据库表 [英] Update MS Access database table using update and Aggregrate sum() function

查看:57
本文介绍了使用 update 和 Aggregrate sum() 函数更新 MS Access 数据库表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的访问数据库中有两个表表1(员工姓名,员工编号,员工工资)表2(员工姓名,员工编号,总工资)这些表使用员工姓名"和员工编号"关联在一起,如何使用第一个表中的值 Sum(Emp Salary) 更新 table2 中的Total Salary""

I have Two tables in my access database table1(Employee Name,Emp Number,Emp Salary) table2(Employee Name,Emp Number,Total Salary) these tables are related together using "Employee Name" and "Emp Number",How can I update "Total Salary" from table2 with the value Sum(Emp Salary) from first table"

推荐答案

包含聚合函数或使用聚合函数查询的查询不可更新.因此,您可以使用以下命令更新现有表中的数据:

Query, which contains aggregated functions or uses queries with aggregated functions is not updateable. So, you can update the data in existing table using:

  1. 临时表.将汇总结果保存在临时表中,然后使用该临时表中的数据更新工作表.
  2. 如果聚合很简单,并且聚合查询函数可以用域聚合函数(如 DSum 或 CDount)代替,则生成的查询将是可更新的,您可以避免使用临时表

使用域函数查询可能如下所示:

Query with domain function may look like this:

UPDATE Result
SET Result.[Total Salary] = DSum("Emp Salary", "Emp", "Employee Name='" & Replace(Result.EmpName, "'", "''") & _
    "' and [Emp Number]=" & Result.[Emp Number])
WHERE Result.[EmpName] = 'Mohan'
    AND Result.[Emp Number] = 1;

这篇关于使用 update 和 Aggregrate sum() 函数更新 MS Access 数据库表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆