【发布时间】:2014-03-12 11:08:07
【问题描述】:
想根据其他表中的值更新表,但我的表大小非常大,为了优化查询,我想以小块更新表,但我无法这样做。这是我的脚本:
DROP PROCEDURE IF EXISTS sp;
Delimiter //
create procedure sp()
begin
DECLARE i INT unsigned DEFAULT 0;
SET @i =1;
while i < 10 do
update
test t,
(SELECT yearweek(c.currency_date) w,
c.currency _currency, AVG(c.rate) rate
FROM currency c
GROUP BY w,_currency) src
set
t.value = t.value/src.rate,
t.currencyid = 'EUR'
where
w =(yearweek(t.created - interval 1 week) )
and t.currencyid = _currency
limit 20000;
set i = i+1;
end while;
END //
当我调用存储过程时出现错误:
更新和限制的错误使用。
我怎样才能避免这种情况并使用成批的20000 记录更新完整的表
【问题讨论】:
标签: php mysql sql mysql-workbench