访问查询更新麻烦

时间:2020-06-12 01:37:17

标签: sql ms-access

我有一个这样的表: enter image description here


然后,我创建了一个查询,该查询为我提供了每个代码和IBAN的SumOfAmount。查询结果:



enter image description here


这是我使用的查询:

SELECT Tabella.CODE, Tabella.IBAN, Sum(Tabella.AMOUNT) AS SumOfAMOUNT FROM Tabella GROUP BY Tabella.CODE, Tabella.IBAN;

现在,我尝试在表格的“ SUMAMOUNT”列中写入每个“ CODE”和“ IBAN”的金额总和,但我无法达到此目的。

我想要这样的东西:

enter image description here



你能帮助我吗?我正在使用MS ACCESS。 预先谢谢你!

1 个答案:

答案 0 :(得分:2)

使用相关子查询:

select t.*,
       (select sum(t2.amount)
        from tabella as t2
        where t2.code = t.code and t2.iban = t.iban
       ) as summaount
from tabella as t;

编辑:

要更新该列,然后将update与相关的子查询一起使用:

update tabella
    set summacount = (select sum(t2.amount)
                      from tabella as t2
                      where t2.code = tabella.code and t2.iban = tabella.iban
                     );