begin
DECLARE h_aid int;
DECLARE h_num int;
DECLARE b INT(1);
DECLARE rows CURSOR FOR select aid, sum(viewnum) as h_num from ikea_hfarticle_s group by aid;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET b = 1;
SET b=0;
OPEN rows;
FETCH rows INTO h_aid, h_num;
REPEAT
update `ikea_hfarticle` set `viewnum` = h_num where `aid`= h_aid;
FETCH rows INTO h_aid, h_num;
UNTIL b = 1
END REPEAT;
CLOSE rows;
end
select得到结果集,然后循环更新另一张表
最新推荐文章于 2023-07-28 14:50:38 发布