我有一个表,它有一个列顺序\u id,类型int,它们是从1到30的30个数字,并且是唯一的。
我想在mysql中通过查询随机更新这个列,但它们必须是唯一的,并且在1到30之间。我试过这个,但它有问题是“phpmyadmin”在服务器上,并没有显示问题!有人知道问题出在哪里吗?
declare Qid2 int;
declare counter int;
DECLARE done INT DEFAULT FALSE;
declare c cursor
set c = cursor for select order_id from Table_1
open c;
fetch next from c into Qid2;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
while !done DO
set Qid2 = (select RAND()*30);
set counter = ( select count(*) from Table_1 where order_id = Qid2);
while counter!=0 do
Begin
set Qid2 = (select RAND()*30);
set counter =( select count(*) from Table_1 where order_id = Qid2);
End while;
update Table_1
set order_id = Qid2 where current of c;
fetch next from c ;
End while;
close c;
2条答案
按热度按时间vnjpjtjt1#
不需要接近逻辑,我就可以识别出6个错误(如果没有设置分隔符,可能是7个)。我纠正了明显的错误。
qncylg1j2#