Aggregate function in an SQL update query?

前端 未结 6 1829
被撕碎了的回忆
被撕碎了的回忆 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:35

    Or you could use a mix of JBrooks and OMG Ponies answers:

    UPDATE table1
       SET field1 = (SELECT SUM(field2)
                       FROM table2 AS t2
                      WHERE t2.field3 = t1.field3)
      FROM table1 AS t1
    

提交回复
热议问题