这应该工作
update content,( select @row_number:=ifnull(@row_number, 0)+1 as new_position, ContentID from content where CategoryID=1 order by position) as table_positionset position=table_position.new_positionwhere table_position.ContentID=content.ContentID;
但我更喜欢先应用此方法,以取消设置用户定义的变量
set @row_number:=0;
由Mchl添加:
您可以在这样的一条语句中做到这一点
update content,( select @row_number:=ifnull(@row_number, 0)+1 as new_position, ContentID from content where CategoryID=1 order by position) as table_position,( select @row_number:=0) as rowNumberInitset position=table_position.new_positionwhere table_position.ContentID=content.ContentID;



