这里我只描述每个表的基本字段
(此主表用于存储导入列表)
(这是一个用于在处理之前存储数据的临时表。处理完成后,行被移动到tblDonation表。有些行将保留在此表中,status =“Discarded”,Notes =“丢弃原因”。开始阶段状态设置为“新”)
[此表用于处理后存储数据]
我需要一个查询
更新sysImportDonationCS表中的行,其中status =“Discarded”和Notes =“Reason”,并且与同一客户端的sysImportDonationCS.GiftID和tblDonation.GiftNumber匹配(同一客户端是重要的点并通过sysimport连接)。我想出了一个有效的查询,但现在耗时太长了。
查询
UPDATE `sysimportdonationcs` as d INNER JOIN
(SELECT donation.internalTempID as tID from sysimportdonationcs as donation
INNER JOIN sysimport as s1 ON donation.`internalImportID` = s1.internalImportID INNER JOIN tbldonation ON donation.Gift_ID = tbldonation.giftNumber
INNER JOIN sysimport as s2 ON tbldonation.internalImportID = s2.internalImportID
where s1.clientID = S2.clientID AND donation.status = 'NEW' AND donation.internalImportID = $import_id order by tID limit 10) temp on temp.tID = d.internalTempID
SET d.status = 'Discarded', d.notes = 'The job type was incremental and a matching record found in the tblDonation table.' ;
某些状态
我需要优化上述查询才能更快地运行。