将另一个表中的计数插入到主表中

时间:2018-03-06 21:31:37

标签: mysql

我有一张主表和几张额外的表。每一行都是一个人的记录。

我想将附加表中的个人计数作为新列插入到主表中。有一个唯一的ID可以链接这两者。

我找到了这些说明:MySQL: UPDATE table with COUNT from another table?

我的代码是:

SELECT * FROM leeds.salesforce_contacts as allmemcomb
    LEFT OUTER JOIN leeds.leenk_ladder_history as ladhist on allmemcomb.salesforce_id = ladhist.member_id
    LEFT OUTER JOIN leeds_so.leenk_ladder_config as ladconf on ladhist.member_id = ladconf.ladder_config_id

UPDATE allmemb
set count = (
    select count (ladder_change)
    from ladhist where ladhist.member_id = allmembcomb.salesforce_id
        );

但我收到以下错误:

Error Code: 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 'UPDATE allmemb  set count = (   select count (ladder_change)   from ladhist wher' at line 13

想法?

1 个答案:

答案 0 :(得分:0)

在UPDATE之前的语句末尾缺少分号。