我理解你的意思是相同txtShopCode值的记录要按照从1递增更新sort字段值?
如果这样的话,也简单,但是为了方便更新执行,需要增加一个辅助更新字段,名称:num,更新后可删除该字段
假定你的表名为 tname
alter table tname add num INT NOT NULL AUTO_INCREMENT;----增加递增字段
update tname set sort=1 where 1=1;----先将所有sort字段赋初始值1;
update tname m inner join
(select a.txtGuid guid,
(select count(*) from tname where num<=a.num and txtShopCode=a.txtShopCode) sortValue from tname a) n
on m.txtGuid=n.guid
set m.sort=n.sortValue;
alert table tname drop column num;----删除新增字段num
mysql 分组排序更新字段的排序号,大神来分析一下
40- 点赞
- 写回答
- 关注问题
- 收藏
- 复制链接分享
- 邀请回答