How to update ms access database table using update and sum() function?

后端 未结 3 1794
春和景丽
春和景丽 2020-12-21 22:22

I have Two tables in my access database

  • table1(ID,productname,qunatity,remainder)
  • table2(ID,productname,sales)

these tables are rela

3条回答
  •  执念已碎
    2020-12-21 22:58

    Perform an update join by getting the SUM() first like

    UPDATE a 
    SET    a.remainder = x.SaleTotal
    FROM   table1 a 
           INNER JOIN (SELECT productname, SUM(sales) AS SaleTotal 
                       FROM TABLE2 GROUP BY productname) x 
           ON a.productname = x.productname;
    

提交回复
热议问题