第一张桌子18_6_TransactionPartners
列
CompanyName | RegistrationNumber | PreviousCompanyName
----------------------------------------------------------
tests5555 | x | tests444
第二张桌子2_1_journal
柱子
TransactionPartnerName
-------------------------
tests444
尝试使用例如变量 for CompanyName
=来更新两个表,tests111
其中变量 forRegistrationNumber
是x
询问
UPDATE
18_6_TransactionPartners , 2_1_journal
SET
18_6_TransactionPartners.PreviousCompanyName=IF(18_6_TransactionPartners.RegistrationNumber = ?, 18_6_TransactionPartners.CompanyName, 18_6_TransactionPartners.PreviousCompanyName),
18_6_TransactionPartners.CompanyName=IF(18_6_TransactionPartners.RegistrationNumber = ?, ?, 18_6_TransactionPartners.CompanyName),
2_1_journal.TransactionPartnerName=IF(2_1_journal.TransactionPartnerName = 18_6_TransactionPartners.PreviousCompanyName, 18_6_TransactionPartners.CompanyName, 2_1_journal.TransactionPartnerName)
结果得到
第一张桌子18_6_TransactionPartners
列
CompanyName | RegistrationNumber | PreviousCompanyName
----------------------------------------------------------
tests111 | x | tests5555
表格18_6_TransactionPartners
一切正常(没有问题;表格只是为了显示情况)
但是第二张桌子2_1_journal
得到
柱子
TransactionPartnerName
-------------------------
tests555
然而预计会得到tests111
查询有问题2_1_journal.TransactionPartnerName=IF(2_1_journal.TransactionPartnerName = 18_6_TransactionPartners.PreviousCompanyName, 18_6_TransactionPartners.CompanyName, 2_1_journal.TransactionPartnerName)
吗?
假设,查询首先必须将值从 复制CompanyName
到PreviousCompanyName
。然后在中插入新值CompanyName
。然后插入TransactionPartnerName
.
但不是。从我的观点来看,它不是CompanyName
价值,而是PreviousCompanyName
价值。还是首先插入表中2_1_journal
?
请建议什么是正确的查询