Aggregate function in an SQL update query?

前端 未结 6 1834
被撕碎了的回忆
被撕碎了的回忆 2020-12-02 10:48

I\'m trying to set the value in one table to the sum of the values in another table. Something along these lines:

UPDATE table1
SET field1 = SUM(table2.fiel         


        
6条回答
  •  借酒劲吻你
    2020-12-02 11:27

    UPDATE t1
    SET t1.field1 = t2.field2Sum
    FROM table1 t1
    INNER JOIN (select field3, sum(field2) as field2Sum
       from table2
      group by field3) as t2
    on t2.field3 = t1.field3  
    

提交回复
热议问题