随机更新条件为 `Status`=1 结果中的一条数据
update crosscomponents set Status=0 where ID =
( SELECT ID from ( SELECT ID from crosscomponents where `Status`=1 ORDER BY RAND() LIMIT 0,1 ) as a );
更新范围内的随机一条数据
update crosscomponents set `Status`=1
where ID = FLOOR( 1 + RAND() * 250);
//FLOOR(start_num + RAND() * (end_num - start_num + 1))
可以在navicat中做成事件,定时随机更新数据,造成动态效果
事件执行注意前后加 BEGIN 和 END:
BEGIN
update crosscomponents set Status=0 where ID =
( SELECT ID from ( SELECT ID from crosscomponents where `Status`=1 ORDER BY RAND() LIMIT 0,1 ) as a );
update crosscomponents set `Status`=1
where ID = FLOOR( 1 + RAND() * 250);
SELECT ID from crosscomponents where `Status`=1;
END