sql执行效率优化
$sql = "INSERT INTO dc_temp.{$this->tableName}
(userId,lossLoginDay,lossVouAmount)
(SELECT
userId,loginDay,vouchAmountTotal
FROM server_user_{$this->where['productId']}
WHERE userId IN (
SELECT userId FROM dc_temp.{$this->tableName} GROUP BY userId
)
) ON DUPLICATE KEY UPDATE
lossLoginDay= IF(lossLoginDay = 0, VALUES(lossLoginDay), lossLoginDay),
lossVouAmount = IF(lossVouAmount = 0.00, VALUES(lossVouAmount), lossVouAmount)";
这个sql主要是更新表{$this->tableName}中的lossLoginDay、lossVouAmount值,当这2个表数据量很大时执行速度非常之慢,而且十分占资源!同志们帮忙给优化一下
hicooy
12 years, 9 months ago