大意是,从SUBJECT表里获取对应的大类PID的对应的数据的SID,然后将这些SID随机的给ARTICLE表里的SID字段赋值;小弟MYSQL不熟悉,请帮忙下
DECLARE @len INT;
DECLARE @i INT;
DECLARE @v INT;
set @len=(select count(*) from jxmsw_subject where pid=1);
set @i=0;
while @i<=@len
begin
set @i=@i+1;
set @v=(select top 1 sid from jxmsw_subject where pid=1 order by newid());
update jxmsw_articles set sid = @v where sid<> 0 and articleid = (select top 1 articleid from jxmsw_articles where articleid not in (select top (@i-1) articleid from jxmsw_articles where sid<> 0) and catid=1 order by articleid asc);
end;
DECLARE @len INT;
DECLARE @i INT;
DECLARE @v INT;
set @len=(select count(*) from jxmsw_subject where pid=1);
set @i=0;
while @i<=@len
begin
set @i=@i+1;
set @v=(select top 1 sid from jxmsw_subject where pid=1 order by newid());
update jxmsw_articles set sid = @v where sid<> 0 and articleid = (select top 1 articleid from jxmsw_articles where articleid not in (select top (@i-1) articleid from jxmsw_articles where sid<> 0) and catid=1 order by articleid asc);
end;
begin
DECLARE len INT;
DECLARE i INT;
DECLARE v INT;
select count(*) into len from jxmsw_subject where pid=1;
set i=0;
while i<=@len do
set i=i+1;
select sid into v from jxmsw_subject where pid=1 order by newid() limit 1;
update jxmsw_articles set sid = v where sid<> 0 and articleid in (select articleid from jxmsw_articles where articleid not in (select articleid from jxmsw_articles where sid<> 0) and catid=1 order by articleid asc);
end while;
end
DECLARE len INT; 这里报错,难道是PHPMYADMIN版本问题,我查看了资料,应该没什么问题才对啊
DECLARE len INT;
DECLARE i INT;
DECLARE v INT;
SELECT count(*),0 INTO len,i FROM jxmsw_subject WHERE pid=1
while i<len
begin
set i=i+1;
select sid into v from jxmsw_subject where pid=1 order by rand() limit 1;
set @sql=concat('update jxmsw_articles set sid=v where sid<>0 and articaleid=(select articleid from jxmsw_articles where articaleid not in(select articleid from jxmsw_articles where sid<>0 limit ',i,') and and catid=1 order by articleid asc limit 1))';
prepare stmt from @sql;
execute stmt;
deallocate prepare stmt;
end
-- 楼主测试一下,我菜鸟
不好意思。 我while都还没学会
把这里改一下
while i<len do
end while学习2楼