UPDATE (SELECT @rownum:=@rownum+3 as rn,id,order_ from
(SELECT id,col1,col2,order_ from
table where 1=1
ORDER BY col asc) h, (SELECT @rownum:=0) t)t1,table t2
set t2.col1=t1.col1 where t2.id=t1.id;
本文探讨了一种使用SQL进行数据更新的高级技巧,通过联接子查询和变量来实现复杂的数据操作,适用于需要批量更新数据场景。
UPDATE (SELECT @rownum:=@rownum+3 as rn,id,order_ from
(SELECT id,col1,col2,order_ from
table where 1=1
ORDER BY col asc) h, (SELECT @rownum:=0) t)t1,table t2
set t2.col1=t1.col1 where t2.id=t1.id;
5122

被折叠的 条评论
为什么被折叠?