参照另一个表更新同一表

时间:2018-07-20 08:24:22

标签: mysql

我正在尝试使用tableB中的值的总和来更新tableA,但是要根据tableA中的日期进行分组。

这是我能拿到的最近的雪茄,但没有:

update tableA set C1Count = (
    select val from (
        select  a.prodind, sum(b.val) as val from tableA a , tableB b
        where b.date BETWEEN a.ActStartC1 and a.ActFinC1
        group by a.prodind) tmp_tbl
    )
    where tableA.prodind = tmp_table.prodind
)

1 个答案:

答案 0 :(得分:0)

这是在mysql中将表从一个表更新到另一个表的示例

XML Schema Violation: Your manifest does not adhere to the current set of XML schema definitions for Office Add-in manifests. (link: https://aka.ms/add-in-manifest-schema-violation)
  - Details: The element 'WebApplicationInfo' in namespace 'http://schemas.microsoft.com/office/mailappversionoverrides/1.1' has incomplete content. List of possible elements expected: 'Authorizations' in namespace 'http://schemas.microsoft.com/office/mailappversionoverrides/1.1'.

对于您的情况,我认为下面应该可以解决

 UPDATE tableB
    INNER JOIN tableA ON tableB.name = tableA.name
    SET tableB.value = IF(tableA.value > 0, tableA.value, tableB.value)
    WHERE tableA.name = 'Joe'

但是我认为您必须提到tableA和tableB之间的显式连接