更新列,使其包含行位置

更新列,使其包含行位置,第1张

更新列,使其包含行位置

这应该工作

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;


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5063240.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-16
下一篇 2022-11-16

发表评论

登录后才能评论

评论列表(0条)

保存