我想在我的 select 语句的结果中使用循环索引“i”,以便将它插入到另一个表中。是像:
set i=0;
while i<25 do
insert into a (x,y,z)
select a,b,i
from table1;
set i= i+1;
end while;
有什么方法可以做到?
最佳答案
完成 :)
我刚刚将变量 i 创建为 @i,一切都解决了。
像这样:
set @i=0;
while @i<25 do
insert into a (x,y,z)
select a,b,@i
from table1;
set @i= @i+1;
end while;
还是谢谢 :)
关于查询中的 MySQL 循环变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23637041/