基于ID匹配的从一个表到另一个表的SQL更新我有一个数据库account numbers和card numbers..我将这些与文件匹配到update任何卡号的帐号,使我只工作帐户号码。我创建了一个视图,将表链接到帐户/卡数据库,以返回Table ID以及相关的帐号,现在我需要更新那些ID与帐号匹配的记录。这是Sales_Import表,其中account number需要更新字段:LeadID AccountNumber147 5807811235150 5807811326185 7006100100007267039这是RetrieveAccountNumber表中,我需要从以下几个方面进行更新:LeadID AccountNumber147 7006100100007266957150 7006100100007267039我试过以下几种方法,但到目前为止没有运气:UPDATE [Sales_Lead].[dbo].[Sales_Import] SET [AccountNumber] = (SELECT RetrieveAccountNumber.AccountNumber
FROM RetrieveAccountNumber
WHERE [Sales_Lead].[dbo].[Sales_Import]. LeadID =
RetrieveAccountNumber.LeadID)它将卡号更新为帐户号,但帐户号将被替换为NULL
3 回答
慕哥6287543
TA贡献1831条经验 获得超10个赞
UPDATE FROM
JOIN
MS SQL
UPDATE Sales_ImportSET Sales_Import.AccountNumber = RAN.AccountNumberFROM Sales_Import SIINNER JOIN RetrieveAccountNumber RANON SI.LeadID = RAN.LeadID;
MySQL和MariaDB
UPDATE Sales_Import SI, RetrieveAccountNumber RANSET SI.AccountNumber = RAN.AccountNumberWHERE SI.LeadID = RAN.LeadID;
喵喔喔
TA贡献1735条经验 获得超5个赞
UPDATE table2 SET table2.col1 = table1.col1, table2.col2 = table1.col2,...FROM table1, table2 WHERE table1.memberid = table2.memberid
呼唤远方
TA贡献1856条经验 获得超11个赞
MERGE
UPDATE ... FROM
MERGE INTO Sales_Import USING RetrieveAccountNumber ON Sales_Import.LeadID = RetrieveAccountNumber.LeadIDWHEN MATCHED THEN UPDATE SET AccountNumber = RetrieveAccountNumber.AccountNumber;
MERGE
添加回答
举报
0/150
提交
取消