本文介绍了更新table1 SET column1 =(SUM(table2 {& table3} WHERE table2_id1 = id1)WHERE id1 = table2_id1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想基于主要应用于表2但包括表3中的单个值的总和来更新表1.

I'd like to update table1 based upon a sum principally applied on table2 but including a single value from table 3.

table2的一列与table1的id列FKd相同,并且总和基于它们的匹配.

table2 has a column that's FKd to table1's id column, and the sum is based upon them matching.

UPDATE table1, table2
SET table1.column1 =
(SELECT SUM( (SELECT constant FROM table3) +
          (SELECT table2.sum_number
           WHERE table2.table2_id1 = table1.id) ) )
WHERE table1.id = table2.table2_id1;

这对我不起作用.

非常感谢!

给出错误

#1064 - You have an error in your SQL syntax; check the manual that corresponds
 to your MySQL server version for the right syntax to use near
 'WHERE table2.table2_id1 = table1.id) ) ) WHERE table1.id = table2.table2_id1;'

推荐答案

UPDATE table1, table2
SET table1.column1 =
(
    SELECT SUM(
        (SELECT constant FROM table3) +
        (SELECT table2.sum_number *** WHERE table2.table2_id1 = table1.id)
    )
)
WHERE table1.id = table2.table2_id1;

上面标有星号的区域中没有"FROM table2,table1".

There is no "FROM table2,table1" in the area marked with astericks above.

这篇关于更新table1 SET column1 =(SUM(table2 {& table3} WHERE table2_id1 = id1)WHERE id1 = table2_id1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 07:11
查看更多