原来是一条条写的,如下:
update cdb_threads set fid=5 where fid=1;
update cdb_threads set fid=6 where fid=2;
update cdb_threads set fid=7 where fid=3;
update cdb_threads set fid=8 where fid=4;
update cdb_threads set fid=14 where fid=38;
update cdb_threads set fid=16 where fid=14;
update cdb_threads set fid=17 where fid=15;
update cdb_threads set fid=18 where fid=16;
update cdb_threads set fid=19 where fid=17;
update cdb_threads set fid=21 where fid=18;
update cdb_threads set fid=22 where fid=19;
update cdb_threads set fid=23 where fid=20;
update cdb_threads set fid=24 where fid=21;
update cdb_threads set fid=25 where fid=37;但是这样更新出现了一个问题,运行完后下一条语句又更新了上一个的值,能不能写一个case类似的语句,判断然后一次性执行?
update cdb_threads set fid=5 where fid=1;
update cdb_threads set fid=6 where fid=2;
update cdb_threads set fid=7 where fid=3;
update cdb_threads set fid=8 where fid=4;
update cdb_threads set fid=14 where fid=38;
update cdb_threads set fid=16 where fid=14;
update cdb_threads set fid=17 where fid=15;
update cdb_threads set fid=18 where fid=16;
update cdb_threads set fid=19 where fid=17;
update cdb_threads set fid=21 where fid=18;
update cdb_threads set fid=22 where fid=19;
update cdb_threads set fid=23 where fid=20;
update cdb_threads set fid=24 where fid=21;
update cdb_threads set fid=25 where fid=37;但是这样更新出现了一个问题,运行完后下一条语句又更新了上一个的值,能不能写一个case类似的语句,判断然后一次性执行?
只把前四条的语句给你,其他的改一下就可以了。update cdb_threads set fid= (case fid when 5 then 1 when 2 then 6 when 3 then 7 when 4 then 8 else fid end);
5 1
6 2
在UPDATE时,工作表连接对照表,替换即可
如果条件比较少的话,yueliangdao0608 的查询最合适,
如果条件比较多的话,wwwwb 的 方案最合适。我就没有什么其他方案了,即使给出来,也差不多。