ACCESS update with subquery

吃可爱长大的小学妹 提交于 2020-08-05 21:37:29

问题


I have a table like this:


Now I'm trying to write in the column "SUMAMOUNT" of the table the sum of amount per "CODE" and "IBAN" but i can't reach this.

I'd want something like this:



I'm using this query but it doesn't work:

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

The precedent query gives me this result:




Can you help me? I'm using MS ACCESS. Thank you in advance!




EDIT: Screenshot of the error:



I can't even try to run it because he ask me to save it. When I try to save, access gives me this error.

回答1:


Consider domain aggregate, DSum, which allows an updateable query. Below assumes code and iban are text types and therefore requires single quote enclosures.

UPDATE tabella t
SET t.sumamount = DSUM("amount", 
                       "tabella",  
                       "code = '" & t.code & "' AND iban = '" & t.iban & '");

(By the way, best practice in databases is to avoid saving calculations in tables. Save resources and simply run queries on data as needed.)



来源:https://stackoverflow.com/questions/62988053/access-update-with-subquery

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!