更新基于或等于列名的mysql数据

时间:2018-03-02 03:54:46

标签: mysql

我有3个表,分别是dr_table,sales_tb和masterfile_tb。 itemcode是INNER JOIN但我的问题是想要根据等于dr_table和sales_tb数据的列名来更新masterfile_tb的数量。会不可能?

这是我的示例代码:

    $sql = "update masterfile_tb a join
           (select t.vicma_code, sum(t.qty) as qty
            from ((select vicma_code, qty
                   from handymandr_tb bc inner join
                        masterfile_tb ait
                        on bc.vicma_code = ait.in_code 
                  ) union all

                  (select  vicma_code, (qty * -1) 
                   from sales_tb slp inner join
                        masterfile_tb ait2
                        on slp.vicma_code = ait2.in_code
                  )
                 ) t
            group by vicma_code
           ) i

handymandr_tb和sales_tb data = masterfile_tb 列名,所以我可以得到每个项目和分支的数量。 例如: 在handymandr_tb或sales_tb 00152分支 有1个数量000000012729,它将在列名00152上的masterfile_tb上更新。

           on a.in_code = i.vicma_code
        set (depends on the branch_code equals to column name) = i.qty ";

- >这是我的dr_table。所有交易清单。我希望branch_code的数据等于mastefile_tb列名,这样我就可以获得每个项目的每个分支的数量 Here's my dr_table. the list of all transactions. i want the data of branch_code will equal to mastefile_tb column name so i can get the qty onhand for every branches for every item

this is my masterfile_tb where the branch_code data of dr_tb will be equal to masterfile_tb so i can update and get the result of each onhand for every branches and item,

这是我的masterfile_tb,其中dr_tb的branch_code数据将等于masterfile_tb,因此我可以更新并获取每个分支和项目的每个结果。

1 个答案:

答案 0 :(得分:0)

参见示例

update ud u inner join sale s on u.id = s.udid set u.assid = s.assid

How can I do an UPDATE statement with JOIN in SQL?