问题
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"
回答1:
Query, which contains aggregated functions or uses queries with aggregated functions is not updateable. So, you can update the data in existing table using:
- Temporary table. Save aggregated results in temporary table and then update working table using data from this temporary table.
- If aggregating is simple and aggregate query functions can be replaced by domain aggregate functions like DSum or CDount, resulting query will be updateable and you can avoid using temporary tables
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;
来源:https://stackoverflow.com/questions/49583983/update-ms-access-database-table-using-update-and-aggregrate-sum-function