UPDATE table1 SET column1 = (SUM(table2{& table3} WHERE table2_id1 = id1) WHERE id1 = table2_id1 [英] UPDATE table1 SET column1 = (SUM(table2{& table3} WHERE table2_id1 = id1) WHERE id1 = table2_id1

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

问题描述

我想根据主要应用于 table2 但包括表 3 中的单个值的总和来更新 table1.

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.

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

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆